Hi,
We had an assignment to reverse a stack "in place" using recursion. The following member functions are available- IsFull(),IsEmpty(), Push(),Pop(),Top(). I've been thinking about this for a long time but I just cant get it. Here is what I have -
Code:
void ReverseStack(Stack& intStack)
{
if(intStack.IsEmpty())
return;
int temp = intStack.Pop();
ReverseStack(intStack);
intStack.Push(temp);
}
I know it is wrong and in effect clears the stack and then pushes them back in the same order. Can anyone give me any hints or tips on how to approach this ? any help will be appreciated, thanks!