package Demo1;
public class Main {
static void bubbleSort(int a[]){
int length=a.length;
for(int i=0;i<length;i++){
for(int j=1;j<length-i;j++){
if(a[j-1]>a[j]){
int num=a[j-1];
a[j-1]=a[j];
a[j]=num;
}
}
}
}
static void quickSort(int a[],int left,int right){
if(left<right){
int temp=a[left];
int i=left;
int j=right;
while (i<j){
while (i<j&&a[j]>=temp)//至少一个要有=
j--;
a[i]=a[j];
while (i<j&&a[i]<temp)
i++;
a[j]=a[i];
}
a[i]=temp;
quickSort(a,left,i-1);
quickSort(a,j+1,right);
}
return;
}
public static void main(String[] args) {
long totalMilliSeconds1 = System.currentTimeMillis();
int maxn=100000;
int a[]=new int[maxn];
for(int i=0;i<maxn;i++){
a[i]= (int) (Math.random()*maxn);
}
long totalMilliSeconds2 = System.currentTimeMillis();
// bubbleSort(a);
quickSort(a,0,maxn-1);
for(int i=0;i<maxn;i++){
System.out.print(a[i]+" ");
}
System.out.println("");
long totalMilliSeconds3 = System.currentTimeMillis();
// System.out.println(totalMilliSeconds3-totalMilliSeconds1);
System.out.println(totalMilliSeconds3-totalMilliSeconds2);
}
}
05-18
1064
08-19
3195