OK, first of all, what does that variable "x" stand for in popStack(S1,x) and pushStack(S2,x), and why would the popStack function even have parameters??
@viliml - the first parameter is obviously the stack being popped. The second parameter is the element being popped. Conceptually, a stack's pop function can either return the element popped off the stack or discard it. While the standard stack class discards the element that is popped, not all stack implementers take this view. So, the 'x' argument to pop, while not "standard", is certainly not unexpected.
This code smells like C code written in C++. The 'x' parameter must be a reference, therefor it must be C++. But the 'S1' and 'S2' parameters make this look like C code. To be more C++ish, S1 and S2 should be objects on which member functions are called. Such as:
Yes. I'm saying that you could implement a stack to return the popped value in x. I understand that it's not standard, and the "normal" way is to store top and then pop, but there is nothing inherently inconsistent with returning the popped value in x.
void popStack(Stack& s, Element& value);
std::stack does not do it this way. I would not do it this way. But the sample code above implies that the stack functions in question do it this way. I'm just saying it is not inconceivable for a popStack function to have these parameters. That's all.
I would guess that x becomes the popped stack item.
It's pretty simple assignment. A stack is a LIFO structure. Last in is the first out. Like a stack of plates or something. You can put a plate on top of the stack (push), and you can remove a plate from the top (pop).
So just draw a picture of what the stack looks like after each line of code. I'm assuming that a popped item goes into x. So maybe just draw a circle labelled x, and after popStack(S1,x);, put 2 in that circle, etc.
I found this link which uses the same popStack(S1, x), but it's pseudocode.