A linear queue, also known as a simple queue, is a basic implementation of a queue data structure where elements are added at the rear end and removed from the front end.
• It follows the First In, First Out (FIFO) principle, which means that the element that is added first will be the first one to be removed.
• In a linear queue, elements are stored in a linear manner, similar to a line of people waiting for a service.

The operations supported by a linear queue typically include:
- Enqueue: Adding an element to the rear end of the queue.
- Dequeue: Removing an element from the front end of the queue.
- Peek: Viewing the element at the front of the queue without removing it.
- IsEmpty: Checking if the queue is empty.
- IsFull: Checking if the queue is full (in the case of a fixed-size queue).
Applications of Linear Queue:
Here are the common applications of Linear Queue:

‣ Breadth-First Search (BFS):
Linear queues are used in graph traversal algorithms like BFS. In BFS, nodes are visited in layers (levels), and a queue is used to maintain the order of nodes to be visited next. This ensures that nodes are visited in the order of their distance from the starting node.
‣ Job Scheduling:
In operating systems, linear queues are used for job scheduling. Processes or tasks waiting to be executed are placed in a queue, and the operating system schedules them based on their arrival time or priority. For example, in a CPU scheduling algorithm like Round Robin, a queue is used to store processes awaiting CPU time.
‣ Print Queue Management:
In computer systems, when multiple print jobs are sent to a printer, they are typically managed using a linear queue. Each print job is placed in the queue, and the printer processes them in the order they were received. This ensures fairness in printing and prevents print jobs from getting lost or overwritten.
‣ Buffering and Data Flow Control:
Linear queues are used for buffering and flow control in communication systems. For example, in network communication protocols, packets are placed in a queue at the sender’s end before transmission and dequeued at the receiver’s end. This helps regulate the flow of data and prevents congestion.
‣ Customer Service and Queuing Systems:
Linear queues are commonly used in customer service environments such as banks, airports, and amusement parks. Customers waiting for service form a queue, and they are served in the order they arrived (FIFO). Queue management systems help optimize service efficiency and reduce customer wait times.
‣ Traffic Management:
Linear queues are used in traffic management systems to control the flow of vehicles at intersections, toll booths, and traffic signals. Vehicles waiting at intersections form a queue, and traffic signals or traffic controllers regulate their movement based on the queue’s status.
Here’s a basic implementation of a linear queue in Java:
public class LinearQueue {
private int[] array;
private int front; // Index of the front element
private int rear; // Index of the rear element
private int capacity; // Maximum capacity of the queue
// Constructor to initialize the queue with a given capacity
public LinearQueue(int capacity) {
this.capacity = capacity;
array = new int[capacity];
front = rear = -1; // Initialize front and rear to -1 to indicate an empty queue
}
// Method to check if the queue is empty
public boolean isEmpty() {
return front == -1;
}
// Method to check if the queue is full
public boolean isFull() {
return (rear + 1) % capacity == front;
}
// Method to enqueue an element into the queue
public void enqueue(int element) {
if (isFull()) {
System.out.println("Queue is full. Cannot enqueue.");
return;
}
if (isEmpty()) {
front = 0;
}
rear = (rear + 1) % capacity;
array[rear] = element;
}
// Method to dequeue an element from the queue
public int dequeue() {
if (isEmpty()) {
System.out.println("Queue is empty. Cannot dequeue.");
return -1;
}
int removedElement = array[front];
if (front == rear) {
front = rear = -1; // Reset front and rear to -1 to indicate an empty queue
} else {
front = (front + 1) % capacity;
}
return removedElement;
}
// Method to get the front element of the queue without removing it
public int peek() {
if (isEmpty()) {
System.out.println("Queue is empty. No element to peek.");
return -1;
}
return array[front];
}
public static void main(String[] args) {
LinearQueue queue = new LinearQueue(5); // Create a queue with capacity 5
// Enqueue elements into the queue
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
// Print the front element of the queue
System.out.println("Front element: " + queue.peek());
// Dequeue and print elements from the queue
System.out.println("Dequeued: " + queue.dequeue());
System.out.println("Dequeued: " + queue.dequeue());
System.out.println("Dequeued: " + queue.dequeue());
// Try dequeuing from an empty queue
System.out.println("Dequeued: " + queue.dequeue());
}
}