Stacks and Queues

CMPTR
3rd Edition
ISBN:9781337681872
Author:PINARD
Publisher:PINARD
Chapter8: Using Edge, Mail, And People
Section: Chapter Questions
Problem 8QY
icon
Related questions
Question

Stacks and Queues 

Expert Solution
Step 1:

The given code will result in error as the Queue interface is implemented using ArrayDeque class not ArrayQueue Class.

The output provided in this answer is after the correction in code.

Corrected Code:

 

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        Queue<Integer> q = new ArrayDeque<Integer>();
        for(int i=2;i<10;i+=2)
        q.add(i);
        while(!q.isEmpty())
        System.out.println(q.remove()+" ");
     }
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer