We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Binary Search Tree : Insertion
Binary Search Tree : Insertion
Sort by
recency
|
572 Discussions
|
Please Login in order to post a comment
recursive method to insert a value into a binary search tree (BST)
Python solution:
def insert(self, val): curr = self.root if curr is None: self.root = Node(val) else: while True: if val > curr.info: if curr.right is None: curr.right = Node(val) break else: curr = curr.right else: if curr.left is None: curr.left = Node(val)
break else: curr = curr.left return self.rootMy C code 😎😁