Queue

What is a Queue? 😊

A queue is a data structure that operates on the principle of First In, First Out (FIFO). This means that the first element added to the queue is the first one to be removed. It is like a line of people waiting for a service where the first person in line gets served first.

Basic Operations of a Queue:

  • Enqueue: Adds an element to the rear (end) of the queue.
  • Dequeue: Removes the element from the front of the queue.
  • Front (or Peek): Retrieves the front element without removing it.
  • isEmpty: Checks if the queue is empty.
  • isFull: Checks if the queue is full (applicable if a queue has a fixed size).

Application of Queue 😊

  1. CPU Scheduling: Used in operating systems for managing processes.
  2. Printer Queue: Manages print jobs in the order they are received.
  3. Breadth-First Search (BFS): Utilized in graph traversal algorithms.
  4. Handling Requests in Servers: Queues manage incoming requests in servers.
  5. Simulation of Real-World Scenarios: Modeling scenarios like customer service lines.
  6. Data Streaming: Buffers data in real-time streaming applications.
  7. Task Scheduling: Manages tasks in multi-tasking systems.

Practice Program of Queue:

  1. Basic Queue Implementation: Implement a queue using arrays with basic operations: enqueue, dequeue, and peek.

  2. Reverse a Queue: Write a program to reverse a queue.

  3. Circular Queue Implementation: Implement a circular queue to efficiently utilize space.

  4. Queue using Stacks: Implement a queue using two stacks.

  5. Priority Queue: Implement a priority queue where each element has a priority, and the dequeue operation removes the element with the highest priority.

  6. Pizza parlor accepting maximum M orders. Orders are served in first come first served basis. Order once placed cannot be cancelled. Write java program to simulate the system using circular queue using array.