快速排序

void QuickSort(int data[], int low, int high) { if(low >= high) return; int pKey = data[low]; int l = low, h = high; while(l < h) { while(l < h && data[h] >= pKey) h--; data[l] = data[h]; while(l < h && data[l] < pKey) l++; data[h] = data[l]; } data[l] = pKey; QuickSort(data, low, l - 1); QuickSort(data, h+1, high); } 

 

测试主程序

int main(int argc, char *argv[]) { int a[]={49, 38, 65, 97, 76, 13, 27, 49}; int length = sizeof(a)/sizeof(int); QuickSort(a, 0, length - 1); for(int i = 0; i < sizeof(a)/sizeof(int); i++) cout << a[i] << ' '; cout << endl; return 0; } 

你可能感兴趣的:(测试)