Stacks- Prefix to Infix
Prefix: It is a computer understandable expression format where operators comes first ,next operands
e. g: +ab
Infix : It is a human understandable expression format , where the operators comes in between the operands.
e. g: a + b
In my previous stories ,I have shared different conversions of expressions among prefix, postfix, infix. In this story , let us see the conversion of an expression from prefix to infix format.
Algorithm :
- Start
- Read the prefix expression from the user
- Scan the expression from right to left.
- compare each character
- if the character is an alphabet ,push into the stack.
- if it is an operator then ,push the operator between last 2 pushed alphabets.
- continue the process to the total string.
- Write the expression inserted into the stack from top to bottom, which is actually an infix expression.
- Stop
The above simple steps explain how to approach the conversion of an expression from prefix to infix.
Here comes the program of the conversion from prefix to infix
With this we have completed the stacks topic, now lets move to the queues data structure.
Thanking you.