Пример #1
0
    def append(self, data):
        new_node = node(data)
        current = self.head

        while current.next is not None:
            current = current.next
        current.next = new_node
Пример #2
0
    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!")
Пример #3
0
    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
Пример #4
0
 def __init__(self):
     self.head = node()
Пример #5
0
 def insert(self, data):
     if self.root is None:
         self.root = node(data)
     else:
         self._insert(data, self.root)