i am trying to improve my data-structure knowledge and i was doing one problem in tree now after picking up things from long time i am confused with some things
what i am trying to here is create a binary tree in python but i don't whether from the logic point of view or language point of view my code doesn't work could you help me to improve this code
node_list=[]
curr_node=None
class Tree:
global curr_node
global node_list
def __init__(self,data):
self.data=data
self.left=None
self.right=None
curr_node=self.data
node_list.append(data)
def add_nodes(zelf,data):
if data==None:
pass
else:
if zelf.data<curr_node:
Tree(data)
self.left=data
else:
Tree(data)
self.right=data
def show_tree(self):
if node_list !=None:
print(node_list)
t=Tree(50)
t.add_nodes(16)
t.add_nodes(101)
t.show_tree()