-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainClass.java
93 lines (74 loc) · 3.05 KB
/
MainClass.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.NoSuchElementException;
public class MainClass{
public static void main(String[] args) throws EmptyQueueException {
MutantHashTable<String> table = new MutantHashTable<>(5);
MutantHashTable<String> newTable = new MutantHashTable<>(5);
Queue<String> queue;
Stack<String> stack;
try {
table.insert("this");
table.insert("was");
table.insert("very");
table.insert("exciting");
table.insert("and");
table.insert("fun");
table.insert("to");
table.insert("code");
table.insert("had");
table.insert("not");
table.insert("played");
table.insert("with");
table.insert("data");
table.insert("structures");
table.insert("for");
table.insert("ages");
System.out.println("Original Hash Table after first insert operations:\n");
System.out.println(table.toString());
table.remove("exciting");
table.remove("ages");
System.out.println("Table after remove(\"exciting\") and remove(\"ages\") operations:\n\n");
System.out.println(table.toString());
System.out.println("Number of items in original Hash Table: " + table.count() + "\n\n");
newTable.insert("My");
newTable.insert("name");
newTable.insert("?");
newTable.insert("Y");
newTable.insert("B.");
newTable.insert("K");
System.out.println("Second Hash Table after first insert operations:\n\n");
System.out.println(newTable.toString());
newTable.insert("also");
newTable.insert("known");
newTable.insert("as");
newTable.insert("cyk");
System.out.println("Second Hash Table after first insert(\"also\"), insert(\"known\"), insert(\"as\") and insert(\"cyk\") operations:\n\n");
System.out.println(newTable.toString());
System.out.println("Number of items in second Hash Table: " + newTable.count() + "\n\n");
table.merge(newTable);
System.out.println("Original Hash Table after merging it with second table:\n\n");
System.out.println(table.toString());
System.out.println("Number of items in original Hash Table after merge operation with second table: " + table.count() + "\n\n");
System.out.println("find(\"remove\") operation returns: " + table.find("remove"));
System.out.println();
System.out.println("find(\"name\") operation returns: " + table.find("name"));
System.out.println("\n");
System.out.println("getList(16) returns: " + table.getList(16) + "\n");
System.out.println("getList(7) returns: " + table.getList(7) + "\n");
System.out.println();
System.out.println("table.toStack() operation returns:\n");
stack = table.toStack();
System.out.println(stack.toString());
System.out.println();
System.out.println("table.toQueue() operation returns:\n");
queue = table.toQueue();
System.out.println(queue.toString());
System.out.println("\n");
}
catch (DuplicateKeyException e) {
System.out.println(e.getMessage());
}
catch (NoSuchElementException e) {
System.out.println(e.getMessage());
}
}
}