forked from IvanLu1024/Java-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
42 lines (38 loc) · 1.33 KB
/
Copy pathMain.java
File metadata and controls
42 lines (38 loc) · 1.33 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
package code_08_trie;
import java.util.ArrayList;
/**
* Created by 18351 on 2018/12/26.
*/
public class Main {
public static void main(String[] args) {
System.out.println("Mix of two fiction");
ArrayList<String> words = new ArrayList<>();
if(FileOperation.readFile("mix.txt", words)){
long startTime = System.nanoTime();
BSTSet<String> set = new BSTSet<>();
for(String word: words){
set.add(word);
}
for(String word: words){
set.contains(word);
}
long endTime = System.nanoTime();
double time = (endTime - startTime) / 1000000000.0;
System.out.println("Total different words: " + set.getSize());
System.out.println("BSTSet: " + time + " s");
// ---
startTime = System.nanoTime();
TrieSet trieSet = new TrieSet();
for(String word: words){
trieSet.add(word);
}
for(String word: words){
trieSet.contains(word);
}
endTime = System.nanoTime();
time = (endTime - startTime) / 1000000000.0;
System.out.println("Total different words: " + trieSet.getSize());
System.out.println("Trie: " + time + " s");
}
}
}