You are viewing a single comment's thread. Return to all comments →
recursive method to insert a value into a binary search tree (BST)
def __r_insert(self, current_node, value): if not current_node: current_node = Node(value) if value < current_node.info: current_node.left = self.__r_insert(current_node.left, value) if value > current_node.info: current_node.right = self.__r_insert(current_node.right, value) return current_node def insert(self, val): if not self.root: self.root = Node(val) return self.__r_insert(self.root, 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 →
recursive method to insert a value into a binary search tree (BST)