Write a method reversestack that takes as a parameter a stac


Write a method, reverse_stack, that takes as a parameter a stack object and a queue object whose elements are of the same type. The method reverse_stack uses the queue to reverse the elements of the stack.

Solution

Following is the psuedo code for the required method

function reverse_stack( stack ):

queue q;

while stack is not empty:

top = top element of stack

push back top in queue q

pop the top element from stack

while queue q is not empty:

remove last element from queue q, let it be \'e\'

push \'e\' into stack

//stack is reversed

 Write a method, reverse_stack, that takes as a parameter a stack object and a queue object whose elements are of the same type. The method reverse_stack uses t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site