C Write a function Stack upRotateStack s which returns the u

C++

Write a function Stack upRotate(Stack s) which returns the up-rotation of a stack (the top node is moved to the bottom).

Solution

Implement Queue using Stacks

The problem is opposite of this post. A queue can be implemented using two stacks. Let queue to be implemented be q and stacks used to implement q be stack1 and stack2. q can be implemented in two ways:

We strongly recommend that you click here and practice it, before moving on to the solution.

Method 1 (By making enQueue operation costly) This method makes sure that oldest entered element is always at the top of stack 1, so that deQueue operation just pops from stack1. To put the element at top of stack1, stack2 is used.

Method 2 (By making deQueue operation costly)In this method, in en-queue operation, the new element is entered at the top of stack1. In de-queue operation, if stack2 is empty then all the elements are moved to stack2 and finally top of stack2 is returned.

C++ Write a function Stack upRotate(Stack s) which returns the up-rotation of a stack (the top node is moved to the bottom).SolutionImplement Queue using Stacks

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site