You are viewing a single comment's thread. Return to all 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
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)
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Insertion
You are viewing a single comment's thread. Return to all 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