/** * Quick sort n*logn * * @param array * array * @param low * low * @param high * high * * Double loop outer condition pointer left is less than right inner condition, both sides slide to the middle right to left, left to right loop outer key is placed at the left pointer */ private static void fastSort(int[] array, int low, int high) { if (low >= high) { return; } else { int left = low; int right = high; int key = array[low]; while (left < right) { while (array[right] >= key && left < right) { right--; } array[left] = array[right]; while (array[left] <= key && left < right) { left++; } array[right] = array[left]; } array[left] = key; fastSort(array, low, left - 1); fastSort(array, left + 1, high); } }
[Data Structure] Quick Sort
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326023521&siteId=291194637
Recommended
Ranking