Skip to content
Learnearn.uk » IB Computer Science » Linear Queue

Linear Queue

Linear Queue

Linear Queue

A linear queue, as described in the introduction, follows the FIFO (First-In-First-Out) principle. Elements are added at the rear and removed from the front. It has a fixed size and may become full, causing enqueue operations to fail.

Applications

Linear queues are typically used for:

  • Task Scheduling: Managing processes and tasks in operating systems.
  • Print Job Management: Handling print jobs in printers.
  • Breadth-First Search (BFS): Graph traversal in algorithms.
  • Data Buffering: Ensuring orderly data transfer in networking.
  • Print Spooling: Managing print requests in systems.
  • Call Center Systems: Handling incoming customer calls.
  • Customer Service Chatbots: Processing customer inquiries.
  • Data Processing Pipelines: Sequential data processing.
  • Order Processing: Fulfilling customer orders in retail.

 

Operations

Queue Operations

Enqueue
Adding an element to the back (also known as the rear or tail) of the queue.

Dequeue
Removing and returning the element from the front (also known as the head) of the queue.

Peek
Viewing the element at the front of the queue without removing it.

 

Demo

Linear Queue Interactive Demonstration

Code

Linear Queue Python Code

class LinearQueue:
    def __init__(self):
        self.queue = []

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

    def dequeue(self):
        if not self.is_empty():
            return self.queue.pop(0)
        else:
            print("Queue is empty")

    def is_empty(self):
        return len(self.queue) == 0

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

# Example usage:
if __name__ == "__main__":
    queue = LinearQueue()
    queue.enqueue(1)
    queue.enqueue(2)
    queue.enqueue(3)

    print("Queue:", queue.queue)
    print("Dequeue:", queue.dequeue())
    print("Queue:", queue.queue)
    print("Is empty?", queue.is_empty())
    print("Size:", queue.size())

 

Resources

Google Slides