Last active
May 27, 2016 02:30
-
-
Save onlylemi/478c5ba654d70f0080b9d3063d2730ea to your computer and use it in GitHub Desktop.
【算法】快速排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void quickSort(int[] arr, int low, int high) { | |
if (low < high) { | |
int first = low; | |
int last = high; | |
int key = arr[low]; | |
while (first < last) { | |
while (first < last && key <= arr[last]) { | |
last--; | |
} | |
// 将比第一个小的放到首端 | |
arr[first] = arr[last]; | |
while (first < last && key >= arr[first]) { | |
first++; | |
} | |
// 将比第一个大的放到末端 | |
arr[last] = arr[first]; | |
} | |
arr[first] = key; | |
quickSort(arr, low, first - 1); | |
quickSort(arr, first + 1, high); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment