Write an algorithm to convert enfix expression to postfix form.
Answers
Answered by
0
Answer:
Step 1: Push “(” onto stack, and add “)” to the end of P.
Step 2: Scan P from left to right and repeat steps 3 to 6 for each element of P until the stack is empty.
Step 3: If an operand is encountered, add it to postfix operation.
Step 4: If a left parenthesis is encountered, push it onto stack.
Step 5: If an operator is encountered, then
Repeatedly pop from the stack and each operator (on the top of stack), which has the same precedence as, or higher precedence than operator.
Add operator to stack.
Step 6: If a right parenthesis is encountered, then
Repeatedly pop from stack and add to postfix string.
Remove the left parenthesis.
Step 7: Exit.
Similar questions
Math,
6 months ago
Computer Science,
1 year ago
English,
1 year ago
English,
1 year ago
Math,
1 year ago