forked from IvanLu1024/Java-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVLMain.java
More file actions
40 lines (31 loc) · 1.25 KB
/
Copy pathAVLMain.java
File metadata and controls
40 lines (31 loc) · 1.25 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
package code_10_avl;
import java.util.ArrayList;
public class AVLMain {
public static void main(String[] args) {
System.out.println("Pride and Prejudice");
ArrayList<String> words = new ArrayList<>();
if(FileOperation.readFile("pride-and-prejudice.txt", words)) {
System.out.println("Total words: " + words.size());
AVLTree<String, Integer> map = new AVLTree<>();
for (String word : words) {
if (map.contains(word)){
map.set(word, map.get(word) + 1);
} else{
map.add(word, 1);
}
}
System.out.println("Total different words: " + map.getSize());
System.out.println("Frequency of PRIDE: " + map.get("pride"));
System.out.println("Frequency of PREJUDICE: " + map.get("prejudice"));
System.out.println("is bst:"+map.isBST());
System.out.println("is balanced:"+map.isBalancedTree());
for(String word:words){
map.remove(word);
if(!map.isBST() || !map.isBalancedTree()){
throw new IllegalArgumentException("Error");
}
}
}
System.out.println();
}
}