快速核心思想:
排序演示
排序方法:
代码展示:
int QuickPartition(int[] a, int low, int high) {
int x = a[low];
while (low < high) {
while ((low<high) && a[high] >= x) high--;
a[low] = a[high];
while ((low<high) && a[low] <= x) low++;
a[high] = a[low];
}
a[low] = x;
return low;
}
void QuickSort(int[] a, int low, int high) {
if (low < high) {
int temp = QuickPartition(a, low, high);
QuickSort(a, low, temp - 1);
QuickSort(a, temp + 1, high);
}
}