Skip to content

Queue ADT

Queue (ABC)

A queue is a First-In-First-Out ADT that supports insertion (enqueueing) of elements at one end and removal (dequeueing) of elements from the opposite end. The order in which elements are enqueued is maintained when dequeueing them.

__len__(self) special

Get the total number of elements stored in the queue

Returns:

Type Description
int

count of elements in queue

Source code in queues/queue_custom.py
@abstractmethod
def __len__(self) -> int:
    """Get the total number of elements stored in the queue

    :returns: count of elements in queue
    """
    pass

dequeue(self)

Remove first element of the queue and return it

Returns:

Type Description
Any

first element of queue

Source code in queues/queue_custom.py
@abstractmethod
def dequeue(self) -> Any:
    """Remove first element of the queue and return it

    :return: first element of queue
    """
    pass

enqueue(self, x)

Insert an element to the end of the queue

Parameters:

Name Type Description Default
x Any

element to add to the queue

required
Source code in queues/queue_custom.py
@abstractmethod
def enqueue(self, x: Any) -> None:
    """Insert an element to the end of the queue

    :param x: element to add to the queue
    """
    pass

get_first(self)

Return first element of the queue without removing it

Returns:

Type Description
Any

first element of queue

Source code in queues/queue_custom.py
@abstractmethod
def get_first(self) -> Any:
    """Return first element of the queue without removing it

    :return: first element of queue
    """
    pass

is_empty(self)

Check if queue contains no elements

Returns:

Type Description
bool

True if queue is empty, else False

Source code in queues/queue_custom.py
@abstractmethod
def is_empty(self) -> bool:
    """Check if queue contains no elements

    :return: True if queue is empty, else False
    """
    pass