-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPart2.java
More file actions
95 lines (81 loc) · 3.99 KB
/
MainPart2.java
File metadata and controls
95 lines (81 loc) · 3.99 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.List;
public class MainPart2 {
public static void main(String[] args) {
// create a new hash AVL spell table
HashAVLSpellTable table = new HashAVLSpellTable(10);
// create some spells
Spell spell1 = new Spell("fireball", "fire", 10, "fireball!");
Spell spell2 = new Spell("frostbolt", "ice", 7, "freeze please");
Spell spell3 = new Spell("thunderstorm", "lightning", 9, "I`m going to shock you");
Spell spell4 = new Spell("poison spray", "poison", 5, "sssss");
Spell spell5 = new Spell("shockwave", "lightning", 8, "go pikachu!");
// add the spells to the hash AVL spell table
table.addSpell(new Spell("lightning bolt", "lightning", 11, "go lightning bolt"));
table.addSpell(spell1);
table.addSpell(spell2);
table.addSpell(spell3);
table.addSpell(spell4);
table.addSpell(spell5);
// add more spells to an existing category
table.addSpell(new Spell("flamethrower min", "fire", 6, "foo"));
table.addSpell(new Spell("flamethrower", "fire", 8, "foo better"));
table.addSpell(new Spell("fireball II", "fire", 12,"fireball!!"));
table.addSpell(new Spell("flamethrower II", "fire", 15, "foooooooo!"));
table.addSpell(new Spell("shockwave II", "lightning", 10,"be useful pikachu."));
table.addSpell(new Spell("frost nova", "ice", 4, "chill dude"));
if (table.getNumberSpells() != 12) {
System.out.println("The current number of spells is " + table.getNumberSpells()); // prints the total number of spells
}
System.out.println("The current number of fire spells spells is " + table.getNumberSpells("fire")); // prints the total number of fire spells
// get the top 3 spells in the "fire" category
System.out.println("Top 3 spells in the 'fire' category:");
List<Spell> fireSpells = table.getTopK("fire", 3);
for (Spell s : fireSpells) {
System.out.println(s.toString()); // prints the top 3 spells in fire category in descending order
}
// get the top 3 spells in the "lightning" category
System.out.println("Top 3 spells in the 'lightning' category:");
List<Spell> lightningSpells = table.getTopK("lightning", 3);
System.out.println(lightningSpells);
for (Spell s : lightningSpells) {
System.out.println(s.toString()); // prints the top 3 spells in lightning category in descending order
}
// spell that exists in the table
Spell searchedSpell = table.searchSpell("fire","fireball", 10);
if (searchedSpell != null) {
System.out.println("Spell Found: " + searchedSpell.toString());
} else {
System.out.println("Spell Not Found");
}
// search for a spell that does not exist in the table
searchedSpell = table.searchSpell("fire", "fireball", 11);
if (searchedSpell != null) {
System.out.println("Spell Found: " + searchedSpell.toString());
} else {
System.out.println("Spell Not Found");
}
// search for a spell that does not exist in the table
searchedSpell = table.searchSpell("ice", "fireball", 10);
if (searchedSpell != null) {
System.out.println("Spell Found: " + searchedSpell.toString());
} else {
System.out.println("Spell Not Found");
}
}
}
// TODO: DELETE!!
// public int[] inorder() {
// int[] num = new int[size];
// inorderHelper(root, num, 0);
// return num;
// }
//
// private int inorderHelper(Node node, int[] num, int index) {
// if (node != null) {
// index = inorderHelper(node.left, num, index);
// num[index] = node.get_spell().getPowerLevel();
// index++;
// index = inorderHelper(node.right, num, index);
// }
// return index;
// }