Question: The following questions are to be done in JAVA. 1) If an array is not considered circular, the text suggests that each remove operation must

The following questions are to be done in JAVA.

1) If an array is not considered circular, the text suggests that each remove operation must shift down every remaining element of the queue. An alternative method is to postpone shifting until rear equals the last index of the array. When that situation occurs and an attempt is made to insert an element into the queue, the entire queue is shifted down so that the first element of the queue is in the first position of the array. What are the advantages of this method over performing a shift at each remove operation? What are the disadvantages?

2) what does the following code fragment do to the queue q?

ObjectStack s = new ObjuectStack();

while (!q.isEmpty())

s.push(q.remove());

while (!s.isEmpty())

q.insert(s.pop());

3)Describe how you might implement a queue using two stacks. Hint: If you push elements onto a stack and then pop them all, they appear in reverse order. If you repeat this process, they're now back in order.

Thank you for all the help.

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!