Question

What’s the output of the following code? Queue<Integer> q = new Queue<Integer>(); q.enqueue(30);   q.dequeue(); q.enqueue(40); q.enqueue(20);...

What’s the output of the following code?

Queue<Integer> q = new Queue<Integer>();

q.enqueue(30);

  q.dequeue();

q.enqueue(40);

q.enqueue(20);

q.dequeue();

q.enqueue(80);

System.out.print(q.dequeue());

0 0
Add a comment Improve this question Transcribed image text
Answer #1

\small \color{blue}Answer:\;\;

20

Explanation:
-------------
Queue<Integer> q = new Queue<Integer>();
q.enqueue(30);  // queue is [30], with 30 at front
q.dequeue();    // front=30 is removed, queue is [].
q.enqueue(40);  // queue is [40], with 40 at front
q.enqueue(20);  // queue is [40, 20], with 40 at front
q.dequeue();    // front=40 is removed, queue is [20].
q.enqueue(80);  // queue is [20, 80], with 20 at front
System.out.print(q.dequeue());  // front=20 is removed and printed
Add a comment
Know the answer?
Add Answer to:
What’s the output of the following code? Queue<Integer> q = new Queue<Integer>(); q.enqueue(30);   q.dequeue(); q.enqueue(40); q.enqueue(20);...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT