Write a menu driven program to implement linear queue operations using linked list
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Queue<Integer> queue = new LinkedList<>();
while (true) {
System.out.println("\n1. Add\n2. Remove\n3. Size\n0. Exit");
switch (in.nextLine()) {
case "1":
queue.add(Integer.parseInt(in.nextLine()));
break;
case "2":
if (!queue.isEmpty()) {
System.out.println(queue.remove());
}
break;
case "3":
System.out.println(queue.size());
break;
case "0":
System.exit(0);
}
}
}
}
Comments
Leave a comment