""" queue.py a queue (first-in-first-out) implemented using a linked list $ python queue.py -- queue demo -- Push 1 onto the queue. Push 2 onto the queue. Push 3 onto the queue. Popping queue until empty : 1 2 3. Done. Jim Mahoney | cs.bennington.college | MIT License | March 2021 """ from linked_list import LinkedList, Node class Queue: def __init__(self): self._list = LinkedList() def is_empty(self): return self._list.is_empty() def enqueue(self, value): self._list.push_end_value(value) def dequeue(self): return self._list.pop_begin_value() def main(): print("-- queue demo --") queue = Queue() for i in range(1, 4): queue.enqueue(i) # For queues, push is spelled "enqueue". print(f"Push {i} onto the queue.") print("Popping queue until empty : ", end='') while not queue.is_empty(): value = queue.dequeue() # For queue, pop is spelled "dequeue". print(f" {value}", end='') print(".\nDone.") main()