This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestAVLTree.py
67 lines (61 loc) · 2.2 KB
/
TestAVLTree.py
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
from avl import *
from visualize import *
from random import randint
def main():
# Creates a AVL (balancing binary search tree)
print("Create binary search tree")
myTree = AVLTree()
n = int(
input(
"""
1. Choose a number of nodes to insert into the tree.
2. Generate a random tree with n nodes. Random range of (1-100).
3. Read from an array of keys.
4. Exit.
Enter option: """
)
)
if n == 1:
x = int(input("Enter a number of nodes to insert into the tree: "))
for i in range(1, x + 1):
myTree.insert(AVLTreeNode(i, i))
elif n == 2:
for i in range(1, randint(1, 100)):
myTree.insert(AVLTreeNode(i, i))
elif n == 3:
"""[DEBUG]
The priority ranking is the value and the key is the crime data:
Make sure that the keys that have the most priority are on the top of the array. Its hard to test here since I am doing count+=1 so its
just priority 1..2..3.. being assigned to every value being passed in.
However, the underlying data structure is still the same and working its just about now doing with keys that are different does
it respect the priority order instead of numbers
"""
p = input("Enter the array of strings: ")
list_of_nodes = p.split()
count = 1
for i in range(len(list_of_nodes)):
j = list_of_nodes[i]
# J should be the attributes like location that I am passing in and then the value is the count and the first
# attribute in the array should be near the top of the tree depending on the balancing.
myTree.insert(AVLTreeNode(j, count))
count += 1
else:
print("Exiting...")
exit(0)
# Print out transversal of tree.
print("Print Preorder:")
pre_o = myTree.preorder()
print(pre_o)
print("Print Postorder:")
post_o = myTree.postorder()
print(post_o)
print("Print Inorder:")
in_o = myTree.in_order()
print(in_o)
# Visualize the tree
v = VisualizeData()
dot = v.visualize_avl(myTree)
dot.format = "png"
dot.view(filename="avltree", directory="./visualizations/")
if __name__ == "__main__":
main()