algorithm to copy contents of stack using a while loop
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!
Learn more about our help with Assignments:
C++