You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
|
|
package sort;
|
|
|
|
|
|
|
|
|
|
|
|
public class Sort {
|
|
|
|
/**
|
|
* @param args the command line arguments
|
|
*/
|
|
public static void main(String[] args) {
|
|
int N=100000;
|
|
int start=0;
|
|
int end=1000000;
|
|
|
|
RandomNum rn=new RandomNum();
|
|
int[] A=new int[N];
|
|
// A=rn.RandomGen(N,start,end);
|
|
for(int k=0;k<N;k++){
|
|
A[k]=k;
|
|
}
|
|
|
|
int[] B=A.clone();
|
|
int[] C=A.clone();
|
|
int[] D=A.clone();
|
|
|
|
|
|
SelectionSort s=new SelectionSort();
|
|
MergeSort m=new MergeSort();
|
|
// InsertionSort i=new InsertionSort();
|
|
// QuickSort q=new QuickSort();
|
|
|
|
Stopwatch clock1=new Stopwatch();
|
|
m.sort(A);
|
|
double time1=clock1.elapsedTime();
|
|
|
|
Stopwatch clock2=new Stopwatch();
|
|
s.sort(B);
|
|
double time2=clock2.elapsedTime();
|
|
|
|
// Stopwatch clock3=new Stopwatch();
|
|
// i.sort(C);
|
|
// double time3=clock3.elapsedTime();
|
|
|
|
// Stopwatch clock4=new Stopwatch();
|
|
// q.sort(D);
|
|
// double time4=clock4.elapsedTime();
|
|
|
|
System.out.println("Selection sort:"+time2+"s");
|
|
// System.out.println("Insertion sort:"+time3+"s");
|
|
System.out.println("Merge sort:"+time1+"s");
|
|
// System.out.println("Quick sort:"+time4+"s");
|
|
|
|
|
|
}
|
|
|
|
}
|