-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_60.py
71 lines (42 loc) · 1.11 KB
/
ex_60.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#BST IMPLEMENTATION
class Tree:
def __init__(self,root):
self.root=root
self.leftC=None
self.rightC=None
def insert_Left(self,value):
if self.leftC==None:
self.leftC=Tree(value)
else:
t=Tree(value)
t.leftC=self.leftC
self.leftC=t
#return self.leftC
def insert_Right(self,value):
if self.rightC==None:
self.rightC=Tree(value)
else:
t=Tree(value)
t.rightC=self.rightC
self.rightC=t
#return self.rightC
def get_root(self):
return self.root
def get_rightC(self):
return self.rightC
def get_leftC(self):
return self.leftC
def set_root(self,new_root):
self.root=new_root
return self.root
root=Tree(3)
root.insert_Left(2)
root.insert_Left(1)
root.insert_Left(0)
root.set_root(4)
print(root.get_root())
root.insert_Right(5)
root.insert_Right(7)
root.insert_Right(9)
print(root.get_leftC().get_root())
print(root.get_rightC().get_root())