The act of writing a program to evaluate simple mathematical expressions supplied as strings (for example, given
10) is actually not as trivial as it first appears. Difficulties arise from having to ensure that operator precedence rules are followed (including handling
The act of writing a program to evaluate simple mathematical expressions supplied as strings (for example, given
10) is actually not as trivial as it first appears. Difficulties arise from having to ensure that operator precedence rules are followed (including handling nested parentheses), which makes simply scanning the string and applying operations as they appear an incorrect solution. One way to correctly do this is by first converting the expression into a form known as Reverse Polish Notation, and then deriving the final answer from this form. Both of these steps use a data structure known as a stack.
A stack is an incredibly simple data structure, that despite its simplicity is used very widely in computer science. A stack holds a collection of items, but only provides operations to add/remove items from the top of the stack. It is analagous to a stack of p