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 words = new ArrayList<>();
if (FileOperation.readFile("AVLTree/pride-and-prejudice.txt", words)) {
Collections.sort(words);// 对äºBST æ¥è¯´
// Test AVL Tree
startTIme = System.nanoTime();
AVLTree 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 HashTable
startTIme = System.nanoTime();
HashTable ht = new HashTable<>();
for (String word : words) {
if (ht.contains(word))
ht.set(word, ht.get(word) + 1);
else
ht.add(word, 1);
}
// æ¥è¯¢æä½
for (String word : words) {
ht.contains(word);
}
endTIme = System.nanoTime();
time = (endTIme - startTIme) / 1000000000.0;
System.out.println("HashTable: " + time + " s");
}
}
}