commit
f1d889513a
@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue