-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.py
More file actions
40 lines (34 loc) · 956 Bytes
/
tree.py
File metadata and controls
40 lines (34 loc) · 956 Bytes
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
class Node() :
def __init__(self,value):
self.value = value
self.right = None
self.left = None
# end of constructor
def insert(self, value):
if self.value:
if value < self.value:
if self.left is None:
self.left = Node(value)
else : #its a node having the insert method
self.left.insert(value)
elif value > self.value:
if self.right is None:
self.right = Node(value)
else:
self.right.insert(value)
else:
self.value = value
# end of insert
def printTree(self):
if self.right:
self.right.printTree()
if self.left:
self.left.printTree()
print(self.value)
# end of printTree
# end of class Node
j = Node(5)
# j.insert()
j.insert(9)
j.insert(3)
j.printTree()