-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
80 lines (62 loc) · 2.23 KB
/
Main.java
File metadata and controls
80 lines (62 loc) · 2.23 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
System.out.println("Pride and Prejudice");
long startTIme;
long endTIme;
double time;
ArrayList<String> words = new ArrayList<>();
if (FileOperation.readFile("AVLTree/pride-and-prejudice.txt", words)) {
// Collections.sort(words);// 对于BST 来说
// Test BST
startTIme = System.nanoTime();
BST<String, Integer> bst = new BST<>();
for (String word : words) {
if (bst.contains(word))
bst.set(word, bst.get(word) + 1);
else
bst.add(word, 1);
}
// 查询操作
for (String word : words) {
bst.contains(word);
}
endTIme = System.nanoTime();
time = (endTIme - startTIme) / 1000000000.0;
System.out.println("BST: " + time + " s");
// Test AVL Tree
startTIme = System.nanoTime();
AVLTree<String, Integer> avl = new AVLTree<>();
for (String word : words) {
if (avl.contains(word))
avl.set(word, avl.get(word) + 1);
else
avl.add(word, 1);
}
// 查询操作
for (String word : words) {
avl.contains(word);
}
endTIme = System.nanoTime();
time = (endTIme - startTIme) / 1000000000.0;
System.out.println("AVLTree: " + time + " s");
// Test RBTree
startTIme = System.nanoTime();
RBTree<String, Integer> rbt = new RBTree<>();
for (String word : words) {
if (rbt.contains(word))
rbt.set(word, rbt.get(word) + 1);
else
rbt.add(word, 1);
}
// 查询操作
for (String word : words) {
rbt.contains(word);
}
endTIme = System.nanoTime();
time = (endTIme - startTIme) / 1000000000.0;
System.out.println("RBTree: " + time + " s");
}
}
}