-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
33 lines (28 loc) · 1.01 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Random;
public class Main {
public static void main(String[] args) {
Sortable[] sorts = new Sortable[6];
sorts[0] = new BubbleSort();
sorts[1] = new InsertionSort();
sorts[2] = new MergeSort();
sorts[3] = new QuickSort();
sorts[4] = new SelectionSort();
sorts[5] = new ShellSort();
for (Sortable s: sorts) {
System.out.println(s.getName());
System.out.println(" 比較回数一覧: ");
for (int i=0; i<4; i++) {
int n = (int)Math.pow(10, i+1);
s.Do(generateArrayRandomly(n), n);
System.out.println(" データ数 " + n + " : " + s.getCount() + " (" + s.getExecTimeNano() + " ns)");
}
System.out.println("");
}
}
private static int[] generateArrayRandomly(int n) {
Random r = new Random();
int[] data = new int[n];
for (int i=0; i<n; i++) data[i] = r.nextInt(65535);
return data;
}
}