def dequeue(self): if self.is_empty(): raise EmptyError("Queue is empty.") e = self._head._element self._size -= 1 self._head = self._head._next if self.is_empty(): self._tail == None return e
def dequeue(self): if self.is_empty(): raise EmptyError("Circular queue is empty.") e = self._tail._next._element if self._size == 1: self._tail = None else: self._tail._next = self._tail._next._next self._size -= 1 return e
def __init__(self, arr, merger): if not arr: raise EmptyError('arr should not empty') self._data = list(arr) self._merger = merger self._tree = [None] * (len(arr) * 4) self._build_tree(0, 0, self.size - 1)
def front(self): if self.is_empty(): raise EmptyError('{} is empty'.format(type(self).__name__)) return self._data[self._front]
def dequeue(self): if self.is_empty(): raise EmptyError('{} is empty'.format(type(self).__name__)) return self._dequeue()
def last(self): if self.is_empty(): raise EmptyError("Dequeue is empty.") return self._trailer._prev._element
def first(self): if self.is_empty(): raise EmptyError("Dequeue is empty.") return self._header._next._element
def remove_first(self): if self.is_empty(): raise EmptyError("PositionalList is empty") return super()._delete_node(self._header._next)
def pop(self): if self.is_empty(): raise EmptyError('Stack is empty') return self._data.pop().val
def peek(self): if self.is_empty(): raise EmptyError("Queue is empty.") return self._head._element
def max(self): if self.size > 0: return self._data[0] raise EmptyError('Can not get max when heap is empty')
def tail(self): if self.is_empty(): raise EmptyError('{} is empty'.format(type(self).__name__)) return self._get_tail()
def max_distance(self): if self.root is None: raise EmptyError('empty tree has no distance') return self._depths(self.root.left) + self._depths(self.root.right)
def top(self): if self.is_empty(): raise EmptyError('Stack is empty') return self._data[-1]
def remove_first(self): if self.is_empty(): raise EmptyError("Dequeue is empty.") return self._delete_node(self._header._next)
def peek(self): if self.is_empty(): raise EmptyError("Circular queue is empty.") return self._tail._next._element
def remove_last(self): if self.is_empty(): raise EmptyError("Dequeue is empty.") return self._delete_node(self._trailer._prev)
def top(self): if self.is_empty(): raise EmptyError("Stack is empty.") return self._head._element
def remove_last(self): if self.is_empty(): raise EmptyError("PositionalList is empty") return super()._delete_node(self._trailer._prev)