Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

2/4/2020 Data Structure : Infix Postfix Prefix - Converter & Evaluator

Simple Tools

Note: Do not use spaces in expression. A+B/C or 4+5/3


not A + B / C or 4 + 5 / 3

Infix -> Postfix &


Prefix
This is a simple infix to prefix or postfix Converter.

Enter the Infix expression below in box and press Convert

Type the Expression below without space


format 1: 2+4/5*(5-3)^5^4
format 2: A+B/C*(D-A)^F^H
(NO SPACE)

A+(B*C-(D/E-F)*G)*H

Postfix Table Prefix Table

Convert Evaluate >

Postfix : ABC*DE/F-G*-H*+ | Prefix : +A*-*BC*-/DEFGH

By Raj

https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html 1/3
2/4/2020 Data Structure : Infix Postfix Prefix - Converter & Evaluator

Sr. no. Expression Stack Postfix

0 A ( A

1 + (+ A

2 ( (+( A

3 B (+( AB

4 * (+(* AB

5 C (+(* ABC

6 - (+(- ABC*

7 ( (+(-( ABC*

8 D (+(-( ABC*D

9 / (+(-(/ ABC*D

10 E (+(-(/ ABC*DE

11 - (+(-(- ABC*DE/

12 F (+(-(- ABC*DE/F

13 ) (+(- ABC*DE/F-

14 * (+(-* ABC*DE/F-

15 G (+(-* ABC*DE/F-G

16 ) (+ ABC*DE/F-G*-

17 * (+* ABC*DE/F-G*-

18 H (+* ABC*DE/F-G*-H

https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html 2/3
2/4/2020 Data Structure : Infix Postfix Prefix - Converter & Evaluator

Sr. no. Expression Stack Postfix

19 ) ABC*DE/F-G*-H*+

Algorithm used
Postfix
Step 1: Add '')" to the end of the infix expression
Step 2: Push(o nto the stack
Step 3: Repeat until each character in the infix notation is scanned
IF a(is encountered, push it on the stack
IF an operand (whetheradigit oracharacter) is encountered, add it postfix expression.
IF a ")" is encountered, then
a. Repeatedly pop from stack and add it to the postfix expression until a "(" is encountered.
b. Discard the "(".That is, remove the(from stack and do not add it to the postfix expression
IF an operator O is encountered, then
a. Repeatedly pop from stack and add each operator ( popped from the stack) to the postfix expression which
has the same precedence orahigher precedence than O
b. Push the operator to the stack
[END OF IF]
Step 4: Repeatedly pop from the stack and add it to the postfix expression until the stack is empty
Step 5: EXIT

Prefix
Step 1: Reverse the infix string. Note that while reversing the string you must interchange left and right parentheses.
Step 2: Obtain the postfix expression of the infix expression Step 1.
Step 3: Reverse the postfix expression to get the prefix expression

https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html 3/3

You might also like