def top(self): if self.is_empty(): raise Empty("Stack is empty") if self._maxlen is not None: return self._data[self._current - 1] else: return self._data[-1]
def pop(self): if self._head is None: raise Empty("Stack is empty") e = self._head._element self._head = self._head._next self._size -= 1 return e
def dequeue(self): if self.is_empty(): raise Empty("Queue is empty") answer = self._data[self._front] self._data[self._front] = None self._front = (self._front + 1) % len(self._data) self._size -= 1 return answer
def dequeue(self): if self._head is None: raise Empty("Queue is empty") r = self._head._element self._head = self._head._next self._size -= 1 if self.is_empty(): self._tail = None return r
def dequeue(self): if self.is_empty(): raise Empty("Queue is empty") oldhead = self._tail._next if self._size == 1: self._tail = None else: self._tail._next = oldhead._next self._size -= 1 return oldhead._element
def first(self): if self.is_empty(): raise Empty("Queue is empty") return self._data[self._front]
def pop(self): if self.is_empty(): raise Empty("Stack is empty") return self._data.pop()
def top(self): if self._head is None: raise Empty("Stack is empty") return self._head._element
def delete_last(self): if self.is_empty(): raise Empty("Deque is empty") return self._delete_node(self._tailer._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._tailer._prev._element
def first(self): if self.is_empty(): raise Empty("Deque is empty") return self._header._next._element
def first(self): if self.is_empty(): raise Empty("Queue is empty") head = self._tail._next return head._element