RPN uses a Last In First Out (LIFO) stack. That is, the last variable pushed on the stack is the first variable popped off the stack.
For example, the following expression:
5 4 3 + *
Assuming our stack is initially empty. The first item is an operand (5), so push it onto a stack. Then we encounter the next operand 4 and push it on the stack as well. 4 now becomes the new top of the stack. Then we do the same with 3 which now becomes the newest top of the stack
Our stack now looks like this 5 4 3 <=== top of stack. The number 3 is at the top
Next we encounter the + (plus sign) operator. We must apply it to the two previously encountered operands which are on the top of the stack. We now pop 3 and 4 off the top of the stack and add them since the + (plus) operator is next in the expression to get 7. So we now push the result 7 back on top of the stack.
Our stack now looks like this 5 7 <=== top of stack. The number 7 is at the top
We now have to address our last operand, the * (multiply sign). Now we must pop the top top operands 5 and 7 off the stack and multiply them to get a result of 35.
Finally, we push 35 back on the stack.
Our stack now looks like this 35 <=== top of stack. The number 35 is at the top