4.1.4.2 Queue Operations
Computational Structures
Queues support two primary operations:
- Enqueue (Add an Item): This is like adding a person to the end of the line. In a queue, you add items to the back.
- Dequeue (Remove an Item): This is like serving the person at the front of the line. In a queue, you take items out from the front.
- Additional operations might include checking if the queue is empty, retrieving the element at the front without removing it, and determining the size of the queue.
python
# Built-in module to implement queues in python
from queue import Queue
# Create a new queue
q = Queue ()
# Add people to the queue (Enqueue)
q. put (" Ahmed") # Adds Ahmed to the end of the queue