In: Computer Science
Priority Queue Application:
Use your Java's Priority Queue. Make a priority queue to represent customers being served at the Department of Motor Vehicles.
Code:
import java.util.*;
import java.io.*;
class Main {
        public static void main (String[] args) {
                // Size of the 
        // ArrayList 
        int n = 100; 
  
        // Declaring the ArrayList with 
        // initial size n 
        ArrayList<Integer> arrli 
            = new ArrayList<Integer>(n); 
  
        // Appending new elements at 
        // the end of the list 
        for (int i = 1; i <= n; i++) 
            arrli.add(i);
        
        // creating a priority queue
        PriorityQueue<Integer> pq = new PriorityQueue<>(); 
        Random rand = new Random();  // using random function to generate priority from 0-5
                for(int i=0; i<100; i++){
                        int id = rand.nextInt(5);
                        pq.add(id);
            }
            // printing the list and the queue
      System.out.println("List:");
            System.out.println(arrli);
      System.out.println();
      System.out.println("Queue:");
            System.out.println(pq);
        }
}
Output:
