CS 1723 -- Exercise 2
Evaluate RPN
Due Monday, 8 October 2001


For this exercise you are to finish details of an RPN evaluater that uses the Java Stack class. Here is the algorithm from the Week 5 Lecture notes.


Algorithm to evaluate RPN expression..
   Input: a sequence of numbers and operators (tokens), in RPN.
     (Each number is just a single digit.)
     The algorithm uses the Stack class to hold doubles
   Algorithm:
    For (each token in the sequence, from left to right)
       if (the token is an number) push it on the stack as a double;
       if (the token is an operator) {
           pop the top two items from the stack (two doubles);
           perform the operation on the two items;
           push the result (a double) back on the stack;
       }
   Return the double that is on the stack.  (Only one item should be there.)

Here are some hints and help with various things.


Revision date: 2001-09-29. (Please use ISO 8601, the International Standard.)