Binary Search Tree : Insertion

  • + 0 comments

    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.root