class QuickSort{ int partition(int[] a,int low,int high){ int pivot = a[low]; //第一个元素作为枢轴 while (low < high){ //用low、high搜索枢轴的位置 while (low < high && a[high] >= pivot) high--; a[low] = a[high];//比枢轴小的元素移动到左端 while (low < high && a[low] < pivot) low++; a[high] = a[low];//比枢轴大的元素移动到右端 } a[low] = pivot;//枢轴元素放到最终位置 return low; } public void sort(int[] a,int low,int high){ if (low < high)//递归跳出的条件 { int pivotpos = partition(a,low,high);//划分 sort(a,low,pivotpos-1);//划分左子表 sort(a,pivotpos+1,high);//划分右子表 } } }
标签:枢轴,int,high,pivotpos,low,pivot,排序,快速 From: https://www.cnblogs.com/jixian/p/17155043.html