Fast Sorting algorithm idea: Select a pivot element, treats the sort sequence to divide, after the division the sequence one part is smaller than the pivot element, one part is bigger than the pivot element, then carries on these two good dividing sequences to carry on the above process.
Selects a pivot element for a given range of substrings, and returns the location of the split element after the function is executed.
The element before the split element is less than the pivot element, and the element behind it is greater than this element
int Partition (int array[], int low, int high)
{
Take the first element of the subsequence as the pivot element
int pivot = Array[low];
while (Low < high)
{
Look for the first element less than the pivot element in the second half
while (Low < high && Array[high] >= pivot)
{
--high;
}
Swap this element smaller than the pivot element to the first half
Swap (&array[low], &array[high]);
Look for the first element that is larger than the pivot element from the top part of the trip
while (Low < high && Array[low] <= pivot)
{
++low;
}
Swap this element larger than the pivot element to the second half.
Swap (&array[low], &array[high]);
}
Returns the location of the pivot element
return to Low;
}
Quick Sort
void QuickSort (int array[], int low, int high)
{
if (Low < high)
{
int n = Partition (array, low, high);
QuickSort (array, low, n);
QuickSort (array, n + 1, high);
}
}