def append(self, x): """Add an item to the end of the list.""" _node = Node(x, None, None) if self._head is not None: # if the head is not None the previously of new node become the tail and the # next one None _node._prev = self._tail # previously of new node linked to tail _node._next = None # the next of new new node linked to None self._tail._next = _node # the tail's next linked to new node self._tail = _node # new node become the tail else: # if the head is None there aren't node, so the new node is tail and the head self._head = self._tail = _node
def insertbeforenode(self, data, value_search): new_node = Node(data, None, None) curr_node = self._head while curr_node: if curr_node._value == value_search._value: new_node._prev = curr_node._prev new_node._next = curr_node curr_node._prev = new_node new_node._prev._next = new_node # <-- break # find node and quit loop else: curr_node = curr_node._next