void quickSort(int * const a, int startIndex, int endIndex) { int s = startIndex; int e = endIndex; if (endIndex == startIndex ) return; endIndex--; while (startIndex < endIndex) { int temp = a[startIndex]; while (startIndex < endIndex) { if (a[endIndex] <= temp) { break; } endIndex--; } if (startIndex < endIndex) { //有比startIndex位置小的数 a[startIndex] = a[endIndex]; a[endIndex] = temp; } //从startIndex开始往后找,找一个比temp大的数,此时endIndex上放的是temp temp = a[endIndex]; startIndex++; while (startIndex < endIndex) { if (a[startIndex] > temp) { break; } startIndex++; } if (startIndex < endIndex) { a[endIndex] = a[startIndex]; a[startIndex] = temp; } } //递归 quickSort(a, s, startIndex); quickSort(a, startIndex + 1, e); }