publicclassPaixu{publicstaticvoidmain(String[] args){
int[] array ={5,7,9,6,3,8,2,4};quickSort(array,0, array.length-1);for(int n=0; n<array.length-1; n++){
System.out.print(array[n]+" ");}}publicstaticvoidquickSort(int[] arr, int low, int high){// 递归结束条件:low大于等于high的时候if(low >= high){return;}// 得到基准元素位置
int x =quick(arr, low, high);// 用分治法递归数列的两部分quickSort(arr, low, x-1);quickSort(arr, x +1, high);}privatestatic int quick(int[] arr, int low, int high){// 取第一个位置的元素作为基准元素
int temp = arr[low];
int left = low;
int right = high;// 坑的位置,初始等于temp的位置
int index = low;//大循环在左右指针重合或者交错时结束while( right >= left ){//right指针从右向左进行比较while( right >= left ){//如果右边的数小于基准数,将这个右边的数挪到左边,坑标记右边的数之前的位置if(arr[right]< temp){
arr[left]= arr[right];
index = right;break;}
right--;}//left指针从左向右进行比较while( right >= left ){//如果左边的数大于基准数,将左边的数挪到右边,坑标记左边的数之前的位置if(arr[left]> temp){
arr[right]= arr[left];
index = left;break;}
left++;}}//将基准数移动到之前留下的坑的位置
arr[index]= temp;return index;}}
def quick_sort(arr,low,high):if low>=high:return arr
p=arr[low]
l=low
h=high
while low<high:while low<high and arr[high]>=p:
high=high-1
arr[low],arr[high]=arr[high],arr[low]while low<high and arr[low]<=p:
low=low+1
arr[high],arr[low]=arr[low],arr[high]quick_sort(arr,l,low-1)quick_sort(arr,low+1,h)return arr
arr=[10,7,36,8,9,24,1,12,18,5,65]quick_sort(arr,0,len(arr)-1)print(arr)