We have completed 2 conversions using Stack.
- Infix -> Postfix
- Infix -> Prefix
We need to use Stack and BST for other 4 conversions
- Prefix -> Infix (Result doesn’t have parenthesis)
- Prefix -> Postifx
- Postfix -> Infix (Result doesn’t have parenthesis)
- Postfix -> Prefix
Prefix to Postfix:
- Construct Expression tree from Prefix notation
- Post-order traversal results Postfix expression
- In-order traversal results Infix expression
Algorithm to Construct Expression Tree from Prefix expression:
- Reverse Prefix expression
- Read element by element
- If it is operand then
- Create leaf node (left and right child are NULL)
- Copy the operand into data part
- Push Node’s address onto the Stack
- If it is an operator then
- Create a node
- Copy the operator into data part
- POP address from Stack and assign node->left
- POP address from Stack and assign node->right
- PUSH node’s address onto the Stack
- If there is more input, go to step 2
- If there is no more input, POP the address from stack(which is the root node address)







