forked from jdmcpeek/pretty-print-binary-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_nodes.py
49 lines (35 loc) · 1.03 KB
/
test_nodes.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
# Example of how to use tree_pprint
#
# By therealpeterpython
import tree_pprint
class my_node:
def __init__(self, own = None, left = None, right = None, parent = None):
self.own = own # data attribute
self.left = left
self.right = right
self.parent = parent
def printTree(self):
tree_pprint.pprint(self, "own", "left", "right")
if __name__ == '__main__':
# prep the tree...
#
# root: 2 *(3+12) + !22 / 66
# big_node: a = 2 *(3+12) + !22 / 66
# layer 1
root = my_node('+')
# layer 2
root.left = my_node('*')
root.right = my_node('/')
# layer 3
root.left.left = my_node('2')
root.left.right = my_node('+')
root.right.left = my_node('!')
root.right.right = my_node('6')
# layer 3
root.left.right.left = my_node('3')
root.left.right.right = my_node('12')
root.right.left.left = my_node('22')
big_node = my_node("=",my_node("a"),root)
#root.printTree()
#print("\n\n")
big_node.printTree()