This article is part of article series - "
Datastructures"
Converting a Fully Parenthesized Infix expression into Postfix expression
Analysis:
Five types of input characters
- Opening parentheses
- Operands
- Operators
- Closing parentheses
- New line character (\n)
Pseudocode:
********************************************************
Function : main
Calls : createStack
freeStack
pushIntoStack
popFromStack
Called by : NONE
Input
Parameters: Accepts input expression for processing
Returns : Converts Fully paranthesized INFIX
expression into POSTFIX expression
********************************************************
SET i to 0
GET infix expression from user into input_array
SET var with input_array[i]
CALL createStack
WHILE var != end of string
IF var equals to '(' THEN
CALL pushIntoStack (stack, var)
ELSE IF var is a number THEN
PRINT var
ELSE IF var is an arithmetic operator THEN
CALL pushIntoStack (stack, var)
ELSE IF var equals to ')' THEN
WHILE stackTop != '('
IF stackTop is an arithmetic operator THEN
PRINT stackTop
popFromStack (stack)
ENDIF
ENDWHILE
popFromStack (stack)
ENDIF
SET var with input_expression[INCREMENT i]
ENDWHILE
CALL freeStack (stack)