Public Static voidMyquicksort (int[] Ages,intGirlintBoy ) { //This is a story that stands at the ends of the array and pursues the perfect love//age does not match the Don't//No. 0 Step if(Girl > Boy) {return;} intPerfect =Ages[girl]; inti = girl;//Fen intj = Boy;//Fen intTMP = 0; //look for the termination condition where the male's position is equal to the female.//Fourth Step while(i!=j) {//The first step of the boy's clone to find while(Ages[j] >= perfect && i <j) {J--; } //Step Two, girls, go find while(Ages[i] <= perfect && i <j) {I++; } //at this point each of the clones catches the unsatisfied condition and then swaps//Step three if(i<j) {tmp=Ages[i]; Ages[i]=Ages[j]; AGES[J]=tmp; } } //5th Step//at this point you can jump out of the loop description I and J together, you can get perfectAges[girl] = ages[i];//give the current value to the previous girlAges[i] = perfect;//I and J got perfect.//The offspring of boys and girls are divided into two and multiply .Myquicksort (ages,girl,i-1); Myquicksort (Ages,i+1, boy); //end of Fifth step// the ending}
Reference http://developer.51cto.com/art/201403/430986.htm
Quick Sort, a love story version-java