WikiGalaxy

Personalize

Applications of Queue

1. Printer Queue Management

Queues are widely used in printer management systems to handle print jobs. Each print job is enqueued and processed in the order it was received, ensuring that all documents are printed sequentially without any conflict.


import java.util.LinkedList;
import java.util.Queue;

class PrinterQueue {
    public static void main(String[] args) {
        Queue printQueue = new LinkedList<>();
        printQueue.add("Document1.pdf");
        printQueue.add("Document2.docx");
        printQueue.add("Document3.pptx");

        while (!printQueue.isEmpty()) {
            System.out.println("Printing: " + printQueue.poll());
        }
    }
      

Console Output:

Printing: Document1.pdf

Printing: Document2.docx

Printing: Document3.pptx

Applications of Queue

2. Customer Service Systems

In customer service centers, queues are used to manage the order of customer requests. Customers are served on a first-come, first-served basis, which is efficiently managed using a queue data structure.


import java.util.LinkedList;
import java.util.Queue;

class CustomerService {
    public static void main(String[] args) {
        Queue customerQueue = new LinkedList<>();
        customerQueue.add("Customer1");
        customerQueue.add("Customer2");
        customerQueue.add("Customer3");

        while (!customerQueue.isEmpty()) {
            System.out.println("Serving: " + customerQueue.poll());
        }
    }
      

Console Output:

Serving: Customer1

Serving: Customer2

Serving: Customer3

Applications of Queue

3. Task Scheduling

Task scheduling in operating systems often uses queues. Tasks are scheduled based on their arrival time, and the scheduler processes them in the order they arrive, ensuring fair CPU time allocation.


import java.util.LinkedList;
import java.util.Queue;

class TaskScheduler {
    public static void main(String[] args) {
        Queue taskQueue = new LinkedList<>();
        taskQueue.add("Task1");
        taskQueue.add("Task2");
        taskQueue.add("Task3");

        while (!taskQueue.isEmpty()) {
            System.out.println("Executing: " + taskQueue.poll());
        }
    }
      

Console Output:

Executing: Task1

Executing: Task2

Executing: Task3

Applications of Queue

4. Call Center Systems

Call centers use queues to manage incoming calls. Calls are placed in a queue and handled in the order they are received, ensuring that each caller is attended to in a timely manner.


import java.util.LinkedList;
import java.util.Queue;

class CallCenter {
    public static void main(String[] args) {
        Queue callQueue = new LinkedList<>();
        callQueue.add("Call1");
        callQueue.add("Call2");
        callQueue.add("Call3");

        while (!callQueue.isEmpty()) {
            System.out.println("Answering: " + callQueue.poll());
        }
    }
      

Console Output:

Answering: Call1

Answering: Call2

Answering: Call3

Applications of Queue

5. Breadth-First Search (BFS)

Queues are fundamental in graph algorithms like Breadth-First Search (BFS). BFS uses a queue to explore nodes layer by layer, ensuring all nodes at the present depth level are visited before moving on to the next level.


import java.util.*;

class Graph {
    private int V;
    private LinkedList adj[];

    Graph(int v) {
        V = v;
        adj = new LinkedList[v];
        for (int i = 0; i < v; ++i)
            adj[i] = new LinkedList();
    }

    void addEdge(int v, int w) {
        adj[v].add(w);
    }

    void BFS(int s) {
        boolean visited[] = new boolean[V];
        Queue queue = new LinkedList<>();

        visited[s] = true;
        queue.add(s);

        while (!queue.isEmpty()) {
            s = queue.poll();
            System.out.print(s + " ");

            Iterator i = adj[s].listIterator();
            while (i.hasNext()) {
                int n = i.next();
                if (!visited[n]) {
                    visited[n] = true;
                    queue.add(n);
                }
            }
        }
    }

    public static void main(String args[]) {
        Graph g = new Graph(4);

        g.addEdge(0, 1);
        g.addEdge(0, 2);
        g.addEdge(1, 2);
        g.addEdge(2, 0);
        g.addEdge(2, 3);
        g.addEdge(3, 3);

        System.out.println("Breadth First Traversal starting from vertex 2:");
        g.BFS(2);
    }
}
      

Console Output:

Breadth First Traversal starting from vertex 2:

2 0 3 1

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025