ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
- 快速排序 每次排序选取一个中间值,小的放到左边,大的放到右边; public static void main(String[] args) { // TODO Auto-generated method stub int arry[] = {7,5,4,2,19,10,8,84,4,1,5,6}; quickSort(arry,0,arry.length - 1); for (int i : arry) { System.out.print(i+" "); } } public void quickSort(int []arr,int left,int right){ int i = left; int j = right; int temp = arr[i]; // 是否进入递归 if(i < j){ // 判断是否完成一次快排 while(i < j){ while(arr[j] >= temp && i < j){ j--; } arr[i] = arr[j]; while(arr[i] < temp && i < j){ i++; } arr[j] = arr[i]; } arr[i] = temp; //中间值赋值 if(i!=left) quickSort(arr,left,i-1); if(i!=right) quickSort(arr,i+1,right); } }