Problem

Write a method called shift that accepts a stack of integers and an integer n as parameter...

Write a method called shift that accepts a stack of integers and an integer n as parameters and that shifts n values from the bottom of the stack to the top of the stack. For example, if the stack named s stores [1, 2, 3, 4, 5, 6, 7, 8], and we make the call shift(s, 3); your method should shift the three values at the bottom of the stack to the top of the stack and leave the other values in the same order, producing [4, 5, 6, 7, 8, 3, 2, 1]. Notice that the value that was at the bottom of the stack is now at the top, the value that was second from the bottom is now second from the top, the value that was third from the bottom is now third from the top, and that the five values not involved in the shift are now at the bottom of the stack in their original order. Use one queue as auxiliary storage. You may assume that the parameter n is > 0 and not larger than the number of elements in the stack.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT