快速排序
1.原理
https://blog.csdn.net/adusts/article/details/80882649
2个人代码尝试
public class QuickSort {
public static void quicksort(int number[],int sentry1,int sentry2)
{
int i=sentry1;
int j=sentry2;
int flag=sentry1;
if(i==j)return;
while(i!=j)
{
while(i<j&&number[j]>number[flag])
j--;
//System.out.println(j);
while(i<j&&number[i]<=number[flag])
i++;
//System.out.println(i);
int temp=number[i];
number[i]=number[j];
number[j]=temp;
}
int temp=number[flag];
number[flag]=number[i];
number[i]=temp;
//System.out.println(i);
quicksort(number,sentry1,i);
quicksort(number,i+1,sentry2);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int number[]={6,1,2,7,9,3,4,5,10,8};
quicksort(number,0,9);
for(int i=0;i<number.length;i++)
{
System.out.println(number[i]);
}
}
}