Question: a. What is the output of the following code? import java.util.LinkedList; import java.util.Queue; public class QueueExample { public static void main(String[] args) { }

a. What is the output of the following code? import java.util.LinkedList; import java.util.Queue; public

a. What is the output of the following code? import java.util.LinkedList; import java.util.Queue; public class QueueExample { public static void main(String[] args) { } Queue q = new LinkedList < Integer >(); q.add(5); q.add(4); q.add(6); q.add(3); System.out.println("Elements of queue "+q); Integere q.remove(); System.out.println("removed element-"+ e); e = q.remove(); System.out.println("removed element-"+ e); q.add(7); System.out.println(q); Integer head = q.peek(); System.out.println("head of queue-"+ head); System.out.println(q); int size = q.size((); System.out.println("Size of queue-"+ size);

Step by Step Solution

3.38 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Output Elements of queue 5 4 6 3 removed element5 removed element4 6 3 7 head of queue6 6 3 7 Size o... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!