What would be the contents of q1 after applying the following operations? ArrayQueue q1= new ArrayQueue(5); for(int i = 1, i< 5; i++) q1.offer(i ); while( q1.peek() == 1) q1.poll(); front → rear 1 2 3 4 front → rear 3 4 front → rear 3 4 q1 will be empty

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question
100%
  1. What would be the contents of q1 after applying the following operations?

    ArrayQueue<Integer> q1= new ArrayQueue<Integer>(5);

    for(int i = 1, i < 5; i++)

            q1.offer(i );

    while( q1.peek() == 1)

            q1.poll();

     
    1. front → rear

         1    2    3    4     

       
    2. front → rear

          3              4

       
    3. front → rear

        2       3     4

       
    4. q1 will be empty

       
  2.  
 
 
السؤال 3
 
What would be the contents of q1 after applying the following operations?
ArrayQueue<Integer> q1= new ArrayQueue<Integer>(5);
for(int i = 1, i< 5; i++)
q1.offer(i );
while( q1.peek() ==
1)
q1.poll();
front → rear
1 2 3 4
front → rear
4
front → rear
3 4
q1 will be empty
Transcribed Image Text:What would be the contents of q1 after applying the following operations? ArrayQueue<Integer> q1= new ArrayQueue<Integer>(5); for(int i = 1, i< 5; i++) q1.offer(i ); while( q1.peek() == 1) q1.poll(); front → rear 1 2 3 4 front → rear 4 front → rear 3 4 q1 will be empty
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage