Infix expressions are often translated into postfix form in which the operators appear after their operands (e.g., 3*(2+4) would be 3 2 4 + *). The task is to evaluate a postfix expression with stack.
This is a tutorial exercise in which you can test your browser environment. See the instructions tab for more information.
This is a tutorial exercise in which you can test your browser environment. Below this text should appear a Java applet that has the following sections:
Infix expressions are often translated into postfix form in which the operators appear after their operands (e.g., 3*(2+4) would be 3 2 4 + *). The task is to evaluate a postfix expression with stack.
Drag and drop the items in order from the array into the stack. Each operand is pushed into the stack. Each operator pops two top most operands and executes the corresponding function for them, after which the result is pushed back to the stack. After you have completed the exercise, the value of the expression should remain in the stack.
Check your answer by going into the beginning of the animation (use the Begin button) and stepping through the answer (with the Forward button).
Submit your answer with the Submit button. If the network connection is ok, you should see a new window, and the message stating the number of points you received from the exercise.
Look at the model solution. Note that you can step through the model answer similar to that with your own solution. You can even compare the two solutions step-by-step in order to spot the possible difference.
Reset the exercise again. Note that the expression to be evaluated is a little bit different this time, thus also the solution is different. You can try to solve the exercise again until you are satisfied with the results. In all of the exercises, the best points are always noted down for you. Note, however, that if the reset/model answer functionality is not allowed before the submission, this might be because the number of submissions is limited.
Some addditional problems.
1. read postfix expression token by token 2. if the token is an operand, push it into the stack 3. if the token is a binary operator, 3.1 pop the two top most operands from the stack 3.2 apply the binary operator with the two operands 3.3 push the result into the stack 4. finally, the value of the whole postfix expression remains in the stack