package Algorithm;
public class Day1218 {
public static void quickSort(int[] arr,int low,int high)
{
if(low>=high)
{
return;
}
int key=arr[low],temp;
int start=low,end=high;
while(start<end)
{
while(start<end && key<=arr[end])
{
end--;
}
if(start<end)
{
temp=arr[end];
arr[end]=arr[start];
arr[start]=temp;
}
while(start<end && key>=arr[start])
{
start++;
}
if(start<end)
{
temp=arr[end];
arr[end]=arr[start];
arr[start]=temp;
}
}
//这时候start和end是一样的,指向同一个数
quickSort(arr,low,start-1);
quickSort(arr,end+1,high);
}
public static void main(String[] args) {
int[] a = {10,7,2,1,12,8,9,15};
quickSort(a,0,a.length-1);
for(int s:a)
System.out.println(s);
}
}
来源:CSDN
作者:NWPU_Jack.liu
链接:https://blog.csdn.net/NWPU_LIUBO/article/details/103654794