-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinked_list-Ex13.py
45 lines (42 loc) · 1.13 KB
/
Linked_list-Ex13.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
print("Post Order traversal")
class Node(object):
def __init__(self,data_value):
self.data_value = data_value
self.left = None
self.right = None
def insert_left(self,child):
if self.left is None:
self.left = child
else:
child.left = self.left
self.left = child
def insert_right(self,child):
if self.right is None:
self.right = child
else:
child.right = self.right
self.right = child
def postorder(self,node):
res=[]
if node:
res = self.postorder(node.left)
res = res + self.postorder(node.right)
res.append(node.data_value)
return res
#Root_Node
print("Create Root Node")
root = Node("Root_Node")
#tree_left
print("Create Tree_left")
tree_left = Node("Tree_left")
root.insert_left(tree_left)
#Tree_Right
print("Create tree_Right")
tree_right = Node("Tree_Right")
root.insert_right(tree_right)
#TreeLL
print("Create TreeLL")
treell = Node("treell")
tree_left.insert_left(treell)
print("*******Postorder Traversal****")
print(root.postorder(root))