Skip to content

Instantly share code, notes, and snippets.

@onlylemi
Last active May 27, 2016 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlylemi/478c5ba654d70f0080b9d3063d2730ea to your computer and use it in GitHub Desktop.
Save onlylemi/478c5ba654d70f0080b9d3063d2730ea to your computer and use it in GitHub Desktop.
【算法】快速排序
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