-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.py
More file actions
68 lines (56 loc) · 1.19 KB
/
Copy pathtree.py
File metadata and controls
68 lines (56 loc) · 1.19 KB
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
68
class Node:
def __init__(self, value):
self.value = value
self.left_child = None
self.right_child = None
class Tree(Node):
def __init__(self):
return
def root(self,value):
root=Node(value)
return root
def left(self,root,value):
if root==None:
root=Node(value)
else:
root.left_child=Node(value)
return root.left_child
def right(self,root,value):
if root==None:
root=Node(value)
else:
root.right_child=Node(value)
return root.right_child
def inorder(root):
if root==None:
return
else:
inorder(root.left_child)
print(root.value)
inorder(root.right_child)
def postorder(root):
if root==None:
return
else:
inorder(root.left_child)
inorder(root.right_child)
print(root.value)
def preorder(root):
if root==None:
return
else:
print(root.value)
inorder(root.left_child)
inorder(root.right_child)
Tree=Tree()
root=Tree.root(15)
left=Tree.left(root,8)
right=Tree.right(root,12)
h=Tree.right(left,5)
x=Tree.left(h,4)
p=Tree.right(x,92)
inorder(root)
print(postorder)
postorder(root)
print(preorder)
preorder(root)