How might you use a stack and a queue to determine whether o

How might you use a stack and a queue to determine whether or not a string was a palindrome? If an array is not considered circular, the text suggests that each remove operation must shift down every remaining element of a 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? What does the following code fragment do to the queue q? ObjectStack s = new ObjectStack(); while (!q.isEmpty()) s.push(q.remove()); while (!s.isEmpty()) q.insert (s.pop()); Describe how you might implement a queue using two stacks. Perform a hand simulation of the Multi-Level Feedback Queue Simulation Lab to ensure that you understand the algorithm. Your output should agree with the partial output provided in the lab document.

Solution

1. How might you use a stack and a queue to determine whether or not a string was a palindrome?

STACK

QUEUE

 How might you use a stack and a queue to determine whether or not a string was a palindrome? If an array is not considered circular, the text suggests that eac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site