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.
Some addditional problems.
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:
- Text field (including the text "Calculate the value of the postfix expression using the operand stack.") that contains exercise specific data. If there are no exercise specific data, the text field is not shown. Text field can be located at the top of the applet or at the left side of the applet beside the data structures.
- Drop down list to change the font size
- Animator panel that contains the following buttons to verify your answer: Backward, Forward, Begin, and End.
- Three function buttons to Reset the exercise, look at the Model answer, and Submit your solution.
- Area that displays the data structures needed in the exercise, i.e., the array titled "PostFix expression", and the stack titled "Operand Stack".
Exercise
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 (see the line 2). Each operator (see the lines 3-3.3) pops two top most operands and executes the corresponding function for them, after which the result is pushed back to the stack (note that you can "execute" a number of lines with only single user interface operation). 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 (model) 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. Yet, the limitations only apply with the grading system, not the other functionality. Thus, you can always do the exercise anew (even if the deadline has passed or you have run out of the resubmissions), and there is no harm done whatsoever.