快速排序(C#) 代码实现: public static void QuickSort(int[] a, int startIndex, int endIndex) { if (startIndex > endIndex) return; int keyIndex = Partion(a, startIndex, endIndex); QuickSort(a, startIndex, keyIndex - 1); QuickSort(a, keyIndex + 1, endIndex); } public static int Partion(int[] a, int startIndex, int endIndex) { int temp = 0; int leftMaxIndex = startIndex - 1; int key = a[endIndex]; for (int rightMaxIndex = startIndex; rightMaxIndex < endIndex; rightMaxIndex++) { if (a[rightMaxIndex] <= key) { // 小于等于key的放在左边 temp = a[leftMaxIndex + 1]; a[leftMaxIndex + 1] = a[rightMaxIndex]; a[rightMaxIndex] = temp; leftMaxIndex++; } } // 交换标兵 temp = a[leftMaxIndex + 1]; a[leftMaxIndex + 1] = a[endIndex]; a[endIndex] = temp; return leftMaxIndex + 1; }