In Java Please, Use your language's Priority Queue. Make a priority queue to represent customers being served at the Department of Motor Vehicles.
SOURCE CODE:
import java.util.*;
import java.lang.*;
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
System.out.println("enter the number of customers");
int numOfCusomers=sc.nextInt();
List<String> customersList = new ArrayList<String>();
//list
while(numOfCusomers!=0)
{
customersList.add(sc.nextLine());
numOfCusomers--;
}
System.out.println("Printing List: "+customersList);
PriorityQueue<String> pq = new PriorityQueue<>(); //
priority queue
pq.add("z"); //
pq.add("y");
pq.add("x");
System.out.println("PriorityQueue: " + pq);
}
}
OUTPUT:
enter the number of customers
4
lucky
ram
raju
hema
Printing List: [,lucky, ram, raju, hema]
PriorityQueue: [x, z, y]
Get Answers For Free
Most questions answered within 1 hours.