Answer to Question #300571 in Java | JSP | JSF for Ganesh

Question #300571

Write a menu driven program to implement linear queue operations using linked list

1
Expert's answer
2022-02-23T00:10:07-0500
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);
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS