Beispiel #1
0
 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]
Beispiel #2
0
 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
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
 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
Beispiel #6
0
 def first(self):
     if self.is_empty():
         raise Empty("Queue is empty")
     return self._data[self._front]
Beispiel #7
0
 def pop(self):
     if self.is_empty():
         raise Empty("Stack is empty")
     return self._data.pop()
Beispiel #8
0
 def top(self):
     if self._head is None:
         raise Empty("Stack is empty")
     return self._head._element
Beispiel #9
0
 def delete_last(self):
     if self.is_empty():
         raise Empty("Deque is empty")
     return self._delete_node(self._tailer._prev)
Beispiel #10
0
 def delete_first(self):
     if self.is_empty():
         raise Empty("Deque is empty")
     return self._delete_node(self._header._next)
Beispiel #11
0
 def last(self):
     if self.is_empty():
         raise Empty("Deque is empty")
     return self._tailer._prev._element
Beispiel #12
0
 def first(self):
     if self.is_empty():
         raise Empty("Deque is empty")
     return self._header._next._element
Beispiel #13
0
 def first(self):
     if self.is_empty():
         raise Empty("Queue is empty")
     head = self._tail._next
     return head._element