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()
asked Jan 16, 2022 at 7:49
2
  • " 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... Commented Jan 16, 2022 at 8:09
  • Does this answer your question? How to implement a binary search tree in Python? Commented Jan 16, 2022 at 8:11

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.