Void paixu (int A [], int low, int high;) // use quick sorting
...{
// Low, high indicates the scan range
Int local; // local variable that stores the central index and its value
Int scanup, scandown, mid; // index used for scanning
If (high-low <= 0) // if there are fewer than two elements in the array, return
Return;
Else
If (high-low = 1) // If two elements exist, compare them.
...{
If (APAI [High] <ApaI [low]) // if the last one is smaller than the previous one,
Swap (APAI [low], ApaI [High]); // Switch location
Return;
} // End if
Mid = (low + high)/2; // obtain the central index
Secondary = ApaI [Mid]; // assign the value of the intermediate index to the secondary
Swap (APAI [Mid], ApaI [low]); // Exchange Values of lower-end elements and lower-end Elements
Scanup = low + 1;
Scandown = high; // initialize scan index scanup and scandown
Do ...{
// Scan up from the low terminal table. The scan ends when the scanup enters the high terminal table or when an element greater than the limit is encountered.
While (scanup <= scandown & ApaI [scanup] <= unlock)
Scanup ++;
// Scan down from the high terminal table. It ends when scandown encounters an element smaller than or equal to the limit.
While (piovt <ApaI [scandown])
Scandown --;
// If the two indexes are still in the respective sub-tables, the two elements are misplaced and the two elements are transposed.
If (scanup <scandown)
Swap (APAI [scanup], ApaI [scandown]);
} While (scanup <scandown );
// Copy the partition to the scandown position and separate the two sub-tables
ApaI [low] = ApaI [scandown];
ApaI [scandown] = scanning;
// Perform recursive calls if the low-end table (low to scandown-1) has 2 or more elements
If (low <scandown-1)
Paixu (APAI, low, scandown-1 );
// If the high terminal table (scandown + 1 to high) has two or more elements, perform recursive call.
If (scandown + 1
Paixu (APAI, scandown + 1, high );
}
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