今天研究了一下快速排序法,发现自己还真笨,快速排序法到现在都还没搞清楚。 这个方法用的是递归(每做一次partition,都会将pivotloc放到中间,既把比它小的放左边,比它大的放右边) public void QuickSort(int [] r, int low, int high) { int pivotloc = 0; if (low < high) { pivotloc = Partition(r, low, high); QuickSort(r, low, pivotloc - 1); QuickSort(r, pivotloc+1, high); } } public static int Partition(int[] r, int low, int high) { int temp = r[low]; while (low < high) { if (low < high && temp <= r[high]) { high--; } r[low] = r[high]; if (low < high && r[low] < temp) { low++; } r[high] = r[low]; } r[low] = temp; return low; }