// quicksort// sort arr[] from low to high by quicksort// int [] arr// int low: the start index// int high: the end indexvoid QuickSort(int* arr, int low, int high) {
if (NULL == arr) return;
if (high <= low) return;
int ori_low = low; // the origin low indexint ori_high = high; // the origin high indexintbase = arr[low]; // the basekeywhile (low < high) {
while (low < high && arr[high] >= base) high--;
if (arr[high] < base) arr[low] = arr[high];
while (low < high && arr[low] <= base) low++;
if (arr[low] > base) arr[high] = arr[low];
}
arr[low] = base;
if (low > ori_low) {
QuickSort(arr, ori_low, low - 1);
}
if (low < ori_high) {
QuickSort(arr, low + 1, ori_high);
}
}