def pop(self): """ Remove and return the element at the top of the stack""" if self.is_empty(): raise Empty('Stack if empty') pop_value = self._head._element self._head = self._head._next self._size -= 1 return pop_value
def dequeue(self): """ Remove and return the first element of the queue""" if self.is_empty(): raise Empty('Stack if empty') first_value = self._head._element self._head = self._head._next self._size -= 1 if self.is_empty(): self._tail = None return first_value
def dequeue(self): """ Remove and return the first element at the queue""" if self.is_empty(): raise Empty('Queue is empty') head = self._tail._next if self._size == 1: self._tail = None else: self._tail._next = head._next self._size -= 1 return head._element
def first(self): """ Return but not remove the first element at the queue""" if self.is_empty(): raise Empty('Queue is empty') head = self._tail._next return head._element
def top(self): """ Return but not remove the element at the top of the stack""" if self.is_empty(): raise Empty('Stack if empty') return self._head._element
def delete_last(self): if self.is_empty(): raise Empty(' Deque is empty') return self._delete_node(self._trailer._prev)
def delete_first(self): if self.is_empty(): raise Empty(' Deque is empty') return self._delete_node(self._header._next)
def last(self): if self.is_empty(): raise Empty('Deque is empty') return self._trailer._prev._element
def first(self): if self.is_empty(): raise Empty('Deque is empty') return self._header._next._element