示例#1
0
 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
示例#2
0
 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]
示例#5
0
 def dequeue(self):
     if self.is_empty():
         raise EmptyError('{} is empty'.format(type(self).__name__))
     return self._dequeue()
示例#6
0
 def last(self):
     if self.is_empty():
         raise EmptyError("Dequeue is empty.")
     return self._trailer._prev._element
示例#7
0
 def first(self):
     if self.is_empty():
         raise EmptyError("Dequeue is empty.")
     return self._header._next._element
示例#8
0
 def remove_first(self):
     if self.is_empty():
         raise EmptyError("PositionalList is empty")
     return super()._delete_node(self._header._next)
示例#9
0
 def pop(self):
     if self.is_empty():
         raise EmptyError('Stack is empty')
     return self._data.pop().val
示例#10
0
 def peek(self):
     if self.is_empty():
         raise EmptyError("Queue is empty.")
     return self._head._element
示例#11
0
 def max(self):
     if self.size > 0:
         return self._data[0]
     raise EmptyError('Can not get max when heap is empty')
示例#12
0
 def tail(self):
     if self.is_empty():
         raise EmptyError('{} is empty'.format(type(self).__name__))
     return self._get_tail()
示例#13
0
 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)
示例#14
0
 def top(self):
     if self.is_empty():
         raise EmptyError('Stack is empty')
     return self._data[-1]
示例#15
0
 def remove_first(self):
     if self.is_empty():
         raise EmptyError("Dequeue is empty.")
     return self._delete_node(self._header._next)
示例#16
0
 def peek(self):
     if self.is_empty():
         raise EmptyError("Circular queue is empty.")
     return self._tail._next._element
示例#17
0
 def remove_last(self):
     if self.is_empty():
         raise EmptyError("Dequeue is empty.")
     return self._delete_node(self._trailer._prev)
示例#18
0
 def top(self):
     if self.is_empty():
         raise EmptyError("Stack is empty.")
     return self._head._element
示例#19
0
 def remove_last(self):
     if self.is_empty():
         raise EmptyError("PositionalList is empty")
     return super()._delete_node(self._trailer._prev)