-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66cc4ad
commit e7c337d
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |