/*** * (快速排序) * arr 需要排序的数组 * low 0 * high arr.length-1 */ public class ListTest { public void sort(int arr [],int low ,int high){ int start = low; int end = high; int key = arr[low]; while (start < end){ while(end > start&&arr[end] >= key) end--; if(arr[end] <= key){ int temp = arr[end]; arr[end] = arr [start]; arr[start] = temp; } while(end > start&&arr[start] <= key) start++; if(arr[start] > key){ int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; } } if(start > low){ sort(arr,low,start-1); }if(end < high){ sort(arr,end+1,high); } }
面试 手写排序算法之快速排序
最新推荐文章于 2024-10-09 22:28:58 发布