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 😊
- CPU Scheduling: Used in operating systems for managing processes.
- Printer Queue: Manages print jobs in the order they are received.
- Breadth-First Search (BFS): Utilized in graph traversal algorithms.
- Handling Requests in Servers: Queues manage incoming requests in servers.
- Simulation of Real-World Scenarios: Modeling scenarios like customer service lines.
- Data Streaming: Buffers data in real-time streaming applications.
- Task Scheduling: Manages tasks in multi-tasking systems.
Practice Program of Queue:
Basic Queue Implementation: Implement a queue using arrays with basic operations: enqueue, dequeue, and peek.
Reverse a Queue: Write a program to reverse a queue.
Circular Queue Implementation: Implement a circular queue to efficiently utilize space.
Queue using Stacks: Implement a queue using two stacks.
Priority Queue: Implement a priority queue where each element has a priority, and the dequeue operation removes the element with the highest priority.
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.