Quick Sort, a love story version-java

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.