本帖最后由 杨增坤 于 2013-10-1 21:18 编辑
网上看到的一种选择排序,有大神能注释下我标//的地方吗?看不懂是怎么实现的- public int getMiddle(int[] arr, int low, int high) {
- int tmp = arr[low];
- while (low < high) {
- while (low < high && arr[high] >= tmp)
- high--;
- arr[low] = arr[high]; //
- while (low < high && arr[low] <= tmp)
- low++;
- arr[high] = arr[low]; //
- }
- arr[low] = tmp; //
- return low; //
- }
- public void quick(int[] arr, int low, int high) {
- if (low < high) {
- int mid = getMiddle(arr, low, high);
- quick(arr, low, mid -1);
- quick(arr, mid+1, high);
- }
- }
复制代码 |