#include <iostream> using namespace std; int Partition(int A[], int low, int high) {//一次划分过程 int pivot = A[low]; while (high > low) { while (high > low && pivot <= A[high]) high --; A[low ++] = A[high]; while (high > low && pivot >= A[low]) low ++; A[high --] = A[low]; } A[low] = pivot; return low; } void QuickSort(int A[], int low, int high) {//采用闭区间 int pivotkey; if (low < high) { pivotkey = Partition(A, low, high); QuickSort(A, low, pivotkey-1); QuickSort(A, pivotkey+1, high); } } int main() { int A[] = {5, 2, 9, 7, 1, 0, 6, 8, 4, 3}; int high = sizeof(A)/sizeof(A[0]) - 1; QuickSort(A, 0, high); for (int i = 0; i <= high; i ++) { cout << A[i] << " "; } return 0; }
A[low ++] = A[high];
A[low] = A[high];
谢谢。