def dequeue(self): if self.isEmpty(): raise Empty("Queue is empty.") else: x = self._data.pop(0) self._size -= 1 return x
def add_position(self, e, position): if position == 1 or position == self.size: raise Empty("Please use other Operations for this task") elif position > self.size: raise Empty("Your list size: ", self.size) else: newest = self.Node(e, None) thead = self.Node(0, None) theadnext = self.Node(0, None) thead = self.head for i in range(position - 1): theadnext = thead.next newest.next = theadnext thead.next = None thead.next = newest self.size = self.size + 1
def pop(self): if self.is_empty(): raise Empty("Stack is empty") value = self._head._element self._head = self._head._next self._size = self._size - 1 return value
def last_out(self): if self.is_empty(): raise Empty("Deque is Empty") value = self.data[self.size - 1] self.data.pop() self.size = self.size - 1 return value
def top(self): """Return (but do not remove) the element at the top of the stack. Raise Empty exception if the stack is empty. """ if self.is_empty(): raise Empty('Stack is empty') return self._head._element # top of stack is at head of list
def remove_min(self): """Remove and return (k,v) tuple with minimum key. Raise Empty exception if empty. """ if self.is_empty(): raise Empty('Priority queue is empty.')
def delete_start(self): if self.is_empty(): raise Empty('Linked list is empty') else: self._head = self._head._next self._head._prev = None self._size -= 1
def top(self): """Return (but do not remove) the element at the top of the stack. Raise Empty exception if the stack is empty. """ if self.isEmpty(): raise Empty('Stack is empty') return self.myStack[-1]
def first(self): """Return (but do not remove) the element at the front of the deque. Raise Empty exception if the deque is empty. """ if self.is_empty(): raise Empty("Deque is empty") return self._header._next._element # real item just after header
def last(self): """Return (but do not remove) the last element of deque D; Raise Empty exception if the deque is empty.""" if self.is_empty(): raise Empty('Deque is empty.') return self._data[self._end]
def delete_first(self): """Remove and return the element from the front of the deque. Raise Empty exception if the deque is empty. """ if self.is_empty(): raise Empty("Deque is empty") return self._delete_node(self._header._next) # use inherited method
def delete_last(self): """Remove and return the element from the back of the deque. Raise Empty exception if the deque is empty. """ if self.is_empty(): raise Empty("Deque is empty") return self._delete_node(self._trailer._prev) # use inherited method
def last(self): """Return (but do not remove) the element at the back of the deque. Raise Empty exception if the deque is empty. """ if self.is_empty(): raise Empty("Deque is empty") return self._trailer._prev._element # real item just before trailer
def first(self): """Return (but do not remove) the element at the front of the queue. Raise Empty exception if the queue is empty. """ if self.is_empty(): raise Empty('Queue is empty') return self._head._element # front aligned with head of list
def pop(self): """Remove and return the element from the top of the stack (i.e., LIFO). Raise Empty exception if the stack is empty. """ if self.isEmpty(): raise Empty('Stack is empty') else: return self.myStack.pop()
def pop(self): """Remove and return the element from the top of the stack (i.e., LIFO). Raise Empty exception if the stack is empty. """ if self.is_empty(): raise Empty('Stack is empty') return self._data.pop() # remove last item from list
def top(self): """Return (but do not remove) the element at the top of the stack. Raise Empty exception if the stack is empty. """ if self.is_empty(): raise Empty('Stack is empty') return self._data[-1] # the last item in the list
def delete_last(self): """ Remove and return the element from the back of the deque Raise Empty exception if the deque is empty """ if self.is_empty(): raise Empty('Deque is empty') return self._delete_node(self._trailer._prev)
def pop(self): if self.is_empty(): raise Empty("The stack is empty") else: value = self.head self.head = self.head._next self.size -= 1 return value._element
def remove_last(self): if self.is_empty(): raise Empty('DList is empty') del_element = self._tail._element self._tail = self._tail._prev self._tail._next = None self._size -= 1 return del_element
def last(self): """Return (but do not remove) the last element of deque D; Raise Empty exception if the deque is empty.""" if self.is_empty(): raise Empty('Deque is empty.') back = (self._front + self._size - 1) % len(self._data) return self._data[back]
def first(self): """Return (but do not remove) the first element of deque. Raise Empty exception if the deque is empty """ if self.is_empty(): raise Empty('Deque is empty') return self._data[self._front]
def delete_start(self): if self.is_empty(): raise Empty('Linked list is empty') else: thead = self._head self._tail._next = thead._next self._head = thead._next self._size -= 1
def min(self): """Return but do not remove (k,v) tuple with minimum key. Raise Empty exception if empty. """ if self.is_empty(): raise Empty('Priority queue is empty.') item = self._data[0] return (item._key, item._value)
def delete_first(self): """ Remove and return the element from the front of the deque Raise Empty exception if the deque is empty """ if self.is_empty(): raise Empty('Deque is empty') return self._delete_node(self._header._next)
def pop(self): if self.is_empty(): raise Empty('Stack is empty') else: value = self._head._element self._head = self._head._next self._size -= 1 return value
def dequeue(self): if self.is_empty(): raise Empty('Queue is Empty') value = self._data[self._front] self._data[self._front] = None self._front = self._front + 1 self._size = self._size - 1 return value
def first_out(self): if self.is_empty(): raise Empty("Deque is Empty") value = self.data[self.front] self.data.remove(value) self.front = self.front + 1 self.size = self.size - 1 return value
def first(self): """Return (but do not remove) the element at the front of the queue Raise Empty exception if the queue is empty """ if self.is_empty(): raise Empty("Queue is empty") return self._data[self.front]
def remove_min(self): """Remove and return (k,v) tuple with minimum key. Raise Empty exception if empty. """ if self.is_empty(): raise Empty('Priority queue is empty.') item = self._data.delete(self._data.first()) return (item._key, item._value)