예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
 def delete_last(self):
     if self.is_empty():
         raise Empty(' Deque is empty')
     return self._delete_node(self._trailer._prev)
예제 #7
0
 def delete_first(self):
     if self.is_empty():
         raise Empty(' Deque is empty')
     return self._delete_node(self._header._next)
예제 #8
0
 def last(self):
     if self.is_empty():
         raise Empty('Deque is empty')
     return self._trailer._prev._element
예제 #9
0
 def first(self):
     if self.is_empty():
         raise Empty('Deque is empty')
     return self._header._next._element