void paixu (int a [], int low, int high;) / / use the quick sort method ... (/ / low, high, said scanning range int pivot; / / store the index and the value of the local center variable int scanup, scandown, mid; / / used to scan the index if (high-low =...
void paixu (int a [], int low, int high;) / / use Quick Sort
... (
/ / Low, high, said the scope of the scan
int pivot; / / storage center and the value of the local variable index
int scanup, scandown, mid; / / for the index scan
if (high-low <= 0) / / If the array elements in less than two, then return
return;
else
if (high-low == 1) / / If there are two elements to compare their
... (
if (apai [high]
Swap (apai [low], apai [high ]);// then exchange places
return;
) / / End if
mid = (low + high) / 2; / / get center index
pivot = apai [mid]; / / intermediate index values assigned to pivot
Swap (apai [mid], apai [low ]);// pivot and the lower end of the exchange value of the element
Scanup = low +1;
Scandown = high; / / initialize the scan index scanup and scandown
do ... (
/ / Up from the low-end sub-table scans, when scanup into high-end sub-table, or greater than the pivot of the elements encountered in the end.
while (scanup <= scandown & & apai [scanup] <= pivot)
scanup + +;
/ / Down from the high-end sub-table scans, when scandown encountered less than or equal when the end of the pivot element
while (piovt
scandown -;
/ / If the two indexes are still their child table, then the two elements of dislocation, the transposition of two elements
if (scanup < p>
Swap (apai [scanup], apai [scandown]);
) While (scanup < p>
/ / Will copy scandown pivot position, separate the two sub-tables
apai [low] = apai [scandown];
apai [scandown] = pivot;
/ / If the low end of the child table (low to scandown-1) has two or more elements, then the recursive call
if (low < p>
paixu (apai, low, scandown-1);
/ / If the high-end sub-table (scandown +1 to high) there are two or more elements, then the recursive call
if (scandown +1 < p>
paixu (apai, scandown +1, high);
)
No comments:
Post a Comment