Skip to content

Commit

Permalink
Linked_list-Ex12
Browse files Browse the repository at this point in the history
  • Loading branch information
sinistergeek committed Nov 6, 2023
1 parent 66cc4ad commit e7c337d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Linked_list-Ex12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
print("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 inorder(self,node):
res=[]
if node:
res = self.inorder(node.left)
res.append(node.data_value)
res = res + self.inorder(node.right)
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("*****Inorder traversal*****")
print(root.inorder(root))

0 comments on commit e7c337d

Please sign in to comment.