Stack >> Infix to Postfix : Solved Example [Step by Step]

August 4, 2010 No Comments » Hits : 257





Infix to Postfix Example
Pre-requisite :

ExpressionCurrent SymbolStackOutputComment
A/B^C-DInitial StateNULL-Initially Stack is Empty
/B^C-DANULLAPrint Operand
B^C-D//APush Operator Onto Stack
^C-DB/ABPrint Operand
C-D^/^ABPush Operator Onto Stack because Priority of ^ is greater than Current Topmost Symbol of Stack i.e ‘/’ 
-DC/^ABCPrint Operand
D-/ABC^Step 1 : Now ‘^’ Has Higher Priority than Incoming Operator So We have to Pop Topmost Element .
Step 2 : Remove Topmost Operator From Stack and Print it
D-NULLABC^/Step 1 : Now ‘/’ is topmost Element of Stack Has Higher Priority than Incoming Operator So We have to Pop Topmost Element again.
Step 2 : Remove Topmost Operator From Stack and Print it
D--ABC^/Step 1 : Now Stack Becomes Empty and We can Push Operand Onto Stack
NULLD-ABC^/DPrint Operand
NULLNULL-ABC^/D-Expression Scanning Ends but we have still one more element in stack so pop it and display it

Incoming search terms: