display the contents of a stack in reverse order

1
2
3
4
5
6
7
8
9
10
11
12
/** Display the contents of aStack in reverse order.
 *
 * @pre None.
 *
 * @post None.
 *
 * @param aStack Is the stack to display in reverse order. */
reverse(inout aStack:Stack)
{
   auxStack.createStack()
 
   //... finish me 

Can anyone help me out using only the adt stack operations...
Well this is what I came up with, can anyone better this or verify it?

1
2
3
4
5
6
7
8
reverse(inout aStack:Stack)
{
   auxStack.createStack()
		int i;
		while (i = astack.Pop())
		astack.push(i);
   	cout << i << endl;
}

You have 2 errors in that function.

1.) You are printing out i at the end only
2.) You are pushing into astack instead of auxStack
1
2
3
4
5
6
7
8
reverse(inout aStack:Stack)
{
   auxStack.createStack()
		int i;
		while (i = astack.Pop())
		auxStack.push(i);
   	cout << i << endl;
	     }


OOps, what do you mean I am only printing out i at the end? Isn't that how the function works?
oh, I think I see what you are saying....
Topic archived. No new replies allowed.