Queue Operations

COSC 2306 - First-In, First-Out (FIFO) Data Structure Visualizer

Visual Workspace

Size: 0
Front (Dequeue)
Rear (Enqueue)
Queue is currently empty

Controls

Queue Logic

Items join at the Rear and leave from the Front. Think of a checkout line at a store—the first person in line is the first person served.

# Initialize queue visualizer...

Coding Challenge

Implement a basic Queue class in Python using a list. Your implementation should include the standard operations.

Required Methods:

  • enqueue(item) Adds an item to the end of the queue.
  • dequeue() Removes and returns the item at the front.
  • isEmpty() Returns True if the queue has no items.
  • size() Returns the number of items in the queue.
View queue_implementation.py

Python implementation of a basic Queue:

class Queue:
    def __init__(self):
        self.items = []

    def isEmpty(self):
        return self.items == []

    def enqueue(self, item):
        self.items.append(item)

    def dequeue(self):
        if self.isEmpty():
            return None
        return self.items.pop(0)

    def size(self):
        return len(self.items)