我的QuickSort
代码适用于除2个元素之外的偶数个元素,并且它不会对奇数个元素进行排序。
int QuickSort::Partition(int beg, int end) // Function to Find Pivot Point
{
int p = beg, pivot = list[beg], loc;
for (loc = beg + 1; loc <= end; loc++) {
if (pivot > list[loc]) {
list[p] = list[loc];
list[loc] = list[p + 1];
list[p + 1] = pivot;
p = p + 1;
}
}
return p;
}
void QuickSort::sort(int beg, int end) {
if (beg < end) {
int p = Partition(beg, end); // Calling Procedure to Find Pivot
sort(beg, p - 1); // Calls Itself (Recursion)
sort(p + 1, end); // Calls Itself (Recursion)
}
}