-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworking binary tree
More file actions
39 lines (36 loc) · 1.06 KB
/
working binary tree
File metadata and controls
39 lines (36 loc) · 1.06 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
#Binary Tree Using list
class BT:
def __init__(self, data ):
self.LeftPointer = 0
self.data = data
self.RightPointer = 0
def insert(x, y):
fp = y
if x > dsBT[fp].data:
if dsBT[fp].RightPointer == 0:
dsBT[fp].RightPointer = h
print("here", fp)
elif dsBT[fp].RightPointer != 0:
fp = dsBT[fp].RightPointer
print("here 2 ", fp)
insert( x ,fp)
if x < dsBT[fp].data:
if dsBT[fp].LeftPointer == 0:
dsBT[fp].LeftPointer = h
print("here", fp)
elif dsBT[fp].LeftPointer != 0:
fp = dsBT[fp].LeftPointer
print("here 2 ", fp)
insert( x ,fp)
dsBT = []
l = input("how much data do you want to enter:\n")
for j in range(int(l)):
dsBT.append(BT( None))
for h in range(len(dsBT)):
fp = 0
# video game name
vgn = input(str("enter the game's name:\n"))
dsBT[h].data = vgn
insert(vgn , 0)
for i in range(len(dsBT)):
print(dsBT[i].LeftPointer, dsBT[i].data, dsBT[i].RightPointer)