100% found this document useful (1 vote)
51 views1 page

Infix Postfix Conversion Algorithms

The document describes two algorithms for converting infix notation to postfix notation: 1. A manual algorithm that fully parenthesizes the expression, replaces right parentheses with operators, and removes left parentheses. 2. A stack-based algorithm that reads symbols, outputs operands, pushes operators and parentheses to a stack, and pops operators to the output based on precedence until the entire expression has been processed.

Uploaded by

dangerman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
51 views1 page

Infix Postfix Conversion Algorithms

The document describes two algorithms for converting infix notation to postfix notation: 1. A manual algorithm that fully parenthesizes the expression, replaces right parentheses with operators, and removes left parentheses. 2. A stack-based algorithm that reads symbols, outputs operands, pushes operators and parentheses to a stack, and pops operators to the output based on precedence until the entire expression has been processed.

Uploaded by

dangerman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CSc 227 — Program Design and Development

(McCann)

Infix → Postfix Conversion Algorithms

1. Manual:

(a) Fully parenthesize the the infix expression (one set of parentheses per operator)
(b) Replace the right parentheses with their corresponding operators
(c) Remove the left parentheses

Example: 4 + 5 * 6
(a) ( 4 + ( 5 * 6 ) )

(b) ( 4 ( 5 6 * +

(c) 4 5 6 * +

2. Stack-based:

while there are more symbols to be read


read the next symbol
case:
operand --> output it
’(’ --> push it on the stack
’)’ --> pop operators from the stack to the output
until a ’(’ is popped; do not output the
parentheses
operator --> pop higher- or equal-precedence operators
from the stack to the output; stop before
popping a lower-precedence operator or
a ’(’. Push the operator on the stack.
end case
end while
pop the remaining operators from the stack to the output

Example: A / (B + C) - D

Input Symbol Stack Content Output


A nil A
/ / A
( /( A
B /( AB
+ /(+ AB
C /(+ ABC
) / ABC+
- - ABC+/
D - ABC+/D
<eof> nil ABC+/D-

You might also like