This is an homework assignment, but I've spent about 7 hours on it with no solution. I'm only allowed to use 2 stacks and 2 variables, one to hold the length of the stack and the other to hold an element of the stack.
I need to make stack2 equivalent to stack1, but all different methods I tried they all loop back to what I started with, because the elements are readded back in the same order. Any ideas?
Think carefully. Stacks are a last-in-first-out structure, meaning that the last element that's pushed in is the first to get popped. You have a buffer that allows you to take one element out of the stack and store it indefinitely until you'd like to reinsert it. You also have a counter that could potentially tell you when your element needs to be reinserted. This counter might decrease by one with every "cycle".
Want to watch your teacher lose it?: http://www.cplusplus.com/reference/algorithm/copy/
>:D This is a joke by the way... mostly. I also wanted you to know that programming in C\C++ is not NEARLY as tedious as school makes it seem.
Am I on the right track? This isn't working though...
@Computergeek01, if this wasn't an assignment I could simply do s2 = s1, it works perfectly fine haha.