-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_Sort.ts
62 lines (58 loc) · 1.47 KB
/
test_Sort.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as sort from "./Sort";
import { deepcopy, print } from "./util";
function printSort<T>(d: T[], sortFunc: string) {
let data = deepcopy(d);
let ret;
let start = new Date().getTime();
print(sortFunc," before sort: ", data);
switch (sortFunc) {
case "bubble": {
sort.BubbleSort(data);
break;
}
case "comb": {
sort.CombSort(data);
break;
}
case "select": {
sort.SelectSort(data);
break;
}
case "insert": {
sort.InsertSort(data);
break;
}
case "shell": {
sort.ShellSort(data);
break;
}
case "quick": {
ret = sort.QuickSortRecursive(data);
break;
}
case "quick-nr": {
sort.QuickSort(data);
break;
}
case "quick3way":{
sort.QuickSort3Way(data);
break;
}
case "quickDualPivot": {
sort.QuickSortDualPivot(data);
break;
}
}
print(sortFunc," after sort: ", !ret?data:ret);
print(sortFunc," use times: ", new Date().getTime() - start, "ms");
}
let d = [10,8,3,7,2,4,9,5,4,6];
printSort(d, "bubble");
printSort(d, "comb");
printSort(d, "select");
printSort(d, "insert");
printSort(d, "shell");
printSort(d, "quick-recursive");
printSort(d, "quick-nr");
printSort(d, "quick3way");
printSort(d, "quickDualPivot");