Question: complete following 2 methods: printQueue method and printQueue2 method Write an implementation of the printQueue method which removes and prints each element in the Queue,

complete following 2 methods: printQueue method and printQueue2 method

Write an implementation of the printQueue method which removes and prints each element in the Queue, restoring the queue before it returns. It uses a temporary queue that actually holds the same information as the original queue.

// **************************************************************

// QueueTest.java

//

// A simple driver to manipulate a queue.

//

// **************************************************************

public class QueueTest

{

public static void main(String[] args)

{

QueueADT queue = new LinkedQueue();

//put some stuff in the queue: 0,2,4,..,14

for (int i=0; i<8; i++)

queue.enqueue(i*2);

System.out.println(" ** Initial queue **");

printQueue(queue);

//dequeue 4 items

for (int i=0; i<4; i++)

queue.dequeue();

System.out.println( " ** After dequeueing 4 items **");

printQueue(queue);

//enqueue 7 more: 1,2,..,7

for (int i=0; i<7; i++)

queue.enqueue(i+1);

System.out.println (" ** After enqueueing 7 more items **");

printQueue(queue);

}

//----------------------------------------------------------

// Prints elements of queue, restoring it before returning

//----------------------------------------------------------

public static void printQueue(QueueADT queue)

{

//complete here

}

//write a printQueue method that prints the queue and restores it to its original form without using an auxiliary data structure (stack,queue, etc.). but printQueue2 method can do the same thing as printQueue method.

public static void printQueue2(QueueADT queue)

{// complete here

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!