Answer to Question #8323 in C++ for eugine

Question #8323
algorithm to copy contents of stack using a while loop
1
Expert's answer
2012-04-13T09:17:01-0400
Assuming that you only have push, pop, peek and IsEmpty operations you need two loops, and an intermediate stack:
In the first loop, you pop each item off the stack, and push it onto the temporary stack.
In the second loop, you pop each item off the temporary stack and push it onto both the original stack and the output stack.
&
If you can traverse the start from the bottom, then it isn't a stack copy operation, it's just a memory copy job.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS