Monday, May 24, 2010

Linked Stack C++?

I have a program that uses a linked Stack to store the data. I need to know how I would go about displaying the data inside the stack. I'm having programmers block....

Linked Stack C++?
Something like this:





void DumpStack( Node * pNode ) {


....while (pNode != NULL) {


........cout %26lt;%26lt; pNode-%26gt;data %26lt;%26lt; endl;


........pNode = pNode-%26gt;next;


....}


}
Reply:You could cout the top item, copy it into a second stack, and then pop it. This way, when you've reached the last item in the original stack, the second stack will be an upside down copy of the original. You could either get rid of the first one or, if you need to maintain the order, put everything back into the first stack as you pull it off the second one.





Sorry, I hope you weren't looking for code.

salary survey

No comments:

Post a Comment