Quick Sort algorithm--two little guys throwing carrots

Source: Internet
Author: User
Tags benchmark

     Public Static voidQuickSort (int[] A,intLowintHigh ) {        if(Low <High ) {            intPivotpos = Partition2 (A, Low, high);//completion of pivot positioningQuickSort (A, Low, pivotpos-1); QuickSort (A, Pivotpos+ 1, high); }    }     Public Static intPartition1 (int[] A,intLowintHigh ) {        //two subscript indexes scan from end to end, cut a benchmark radish pivot, leave a pit, back and forth still radish, whether to throw: Compare with pivot value size relationship//Two little man low and high at both ends//There is a pit in the low, then high from him to find radish throw, find than pivot small throw over//The high Place has the pit, from the low place to find the radish to throw, found is bigger than pivot to throw over//after throwing the difference between the end of the 1 pits, then the original dug up the benchmark radish pivot seat, positioning!         intPivot = A[low];//takes the first element of the current table as the pivot value, leaving a pit at the low         while(Low < High) {//loop out of condition, low and high keep approaching until (low = high)             while(Low < High && A[high] >=pivot) {                //If the high radish is larger than the benchmark Radish pivot, do not deal with, higher, go, narrow the rangehigh--; } A[low]= A[high];//High in the radish than the benchmark radish pivot small, throw to the low place of the pit, leaving himself a pit, located high             while(Low < High && A[low] <=pivot) {                //If the low radish is smaller than the benchmark Radish pivot, do not handle it, lower the range .low++; } A[high]= A[low];//Low radish than benchmark radish pivot big, throw to high place pit, oneself left a pit, located at Low} A[low]= pivot;//Put pivot on the last pit, no pits.        returnLow//The loop jumps out, low = high = pivot should be in the pit}

Quick Sort algorithm--two little guys throwing carrots

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.