def append(self, data): new_node = node(data) current = self.head while current.next is not None: current = current.next current.next = new_node
def _insert(self, data, current_node): if data < current_node.data: if current_node.left_child is None: current_node.left_child = node(data) # Use recursion to find the empty left leaf node. else: self._insert(data, current_node.left_child) elif data > current_node.data: # another outer case # when larger if current_node.right_child is None: current_node.right_child = node(data) else: self._insert(data, current_node.right_child) else: print("Data already in tree!")
def append(self, data): new_node = node(data) current = self.head if current.prev is not None: current.prev(new_node) while current.next is not None: current = current.next new_node.prev = current.next current.next = new_node
def __init__(self): self.head = node()
def insert(self, data): if self.root is None: self.root = node(data) else: self._insert(data, self.root)