Module dalpy.queues
This module holds classes related to FIFO queues.
This module contains Queue, an implementation of a FIFO queue, and QueueUnderflowError, an error raised by Queue.
Examples
Initializing, adding, and removing elements from a Queue:
q = Queue()
q.enqueue(1)
q.enqueue(2)
q.dequeue()
The following code will raise a QueueUnderflowError because the second dequeue is done on an empty Queue:
q.dequeue()
q.dequeue()
Classes
class Queue-
This class represents a FIFO queue that has no maximum capacity.
Examples
To initialize a
Queue:q = Queue()To add elements to the end of
q:q.enqueue(1) q.enqueue(2)To remove and return the element at the front of
q(in this casex = 1):x = q.dequeue()To see the element at the front of
q(in this casey = 2):y = q.front()Initializes an empty
QueueinO(1)time.Methods
def dequeue(self)-
Removes the element at the front of this
Queue.This operation runs in
O(1)time with respect to the size of thisQueue.Returns
The element at the front of the
Queuethat was removed. That is, the element that was first added to thisQueueof the elements in it.Raises
QueueUnderflowError- If this
Queueis empty.
def enqueue(self, value)def front(self)def is_empty(self)def size(self)
class QueueUnderflowError (operation)-
This class is used by
Queueto raise errors for operations done on an emptyQueue.Initializes a
QueueUnderflowErrorthat will be raised associated with a particularQueueoperation.Args
operation- a string specifying the operation to raise an error on
Ancestors
- builtins.Exception
- builtins.BaseException