display the contents of a stack in reverse order
Mar 4, 2010 at 4:28am UTC
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...
Mar 4, 2010 at 5:36am UTC
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;
}
Mar 4, 2010 at 7:12am UTC
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
Mar 4, 2010 at 7:16am UTC
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?
Mar 4, 2010 at 7:20am UTC
oh, I think I see what you are saying....
Topic archived. No new replies allowed.