0

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()
im_VS
  • 1
  • *" my code doesn't work"*: please provide a concrete problem description. But review and debug yourself. For instance "zelf" and "self" are not the same... – trincot Jan 16 '22 at 08:09
  • Does this answer your question? [How to implement a binary search tree in Python?](https://stackoverflow.com/questions/5444394/how-to-implement-a-binary-search-tree-in-python) – trincot Jan 16 '22 at 08:11

0 Answers0