Assignment 3: Infix to Postfix Notation
Problem Solving with C++, Spring 2008
Due:
March 12th, 11:53pm
Objectives
The objectives in this assignment are:
1. Practice programming dynamic data structures with
pointers
.
2. Think modularly (in terms of representation) when designing your program. Separate interfaces and
implementations.
3. Learn to plan ahead. This is a big assignment and you will need to work on it in stages.
4. Gain practice coding and debugging algorithms.
Overview
Humans write expressions
3 + 4
and
7
/
9
in
infix
notation – the operator is written between its operands. Com
puters prefer
postfix
notation in which the operator is written to the right of the operand, such as,
3 4 +
and
7 9
/
. To evaluate a complex infix expression, a compiler would first convert the expression to postfix notation
and then evaluate the postfix notation.
The algorithm that converts an infix arithmetic expression (consisting of single digit integers) to a postfix
expression is given below.
Algorithm: Infix to Postfix
Read the given expression into an array named infix. The output will be stored in an array called postfix. You
need a stack to perform the conversion. The steps are as follows:
1. Push a left parentheses into a stack.
2. Append a right parentheses to the end of infix.
3. While the stack is not empty, read infix from left to right and do the following:
(a) If the current character in infix is a digit, copy it to the next element of postfix
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Monte
 Data Structures, Infix notation, Reverse Polish notation, infix

Click to edit the document details