0% found this document useful (0 votes)
2 views3 pages

MDF QC T6 TDH

The document outlines the rules for converting infix expressions to postfix and prefix expressions. It details the procedures for handling operators and operands, including precedence and associativity rules, as well as how to manage parentheses. The conversion processes involve using a stack to organize operators and ensure correct output order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

MDF QC T6 TDH

The document outlines the rules for converting infix expressions to postfix and prefix expressions. It details the procedures for handling operators and operands, including precedence and associativity rules, as well as how to manage parentheses. The conversion processes involve using a stack to organize operators and ensure correct output order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Infix, Postfix and Prefix Expressions

# Rules for the conversion of infix to postfix expression:

1. Print the operand as they arrive.

2. If the stack is empty or contains a left parenthesis on top, push the incoming operator on to the stack.

3. If the incoming symbol is '(', push it on to the stack.

4. If the incoming symbol is ')', pop the stack and print the operators until the left parenthesis is found.

5. If the incoming symbol has higher precedence than the top of the stack, push it on the stack.

6. If the incoming symbol has lower precedence than the top of the stack, pop and print the top of the stack. Then test the incoming operator
against the new top of the stack.

7. If the incoming operator has the same precedence with the top of the stack then use the associativity rules. If the associativity is from left to
right then pop and print the top of the stack then push the incoming operator. If the associativity is from right to left then push the incoming
operator.

8. At the end of the expression, pop and print all the operators of the stack.
# Rules for the conversion of infix to prefix expression :

1. First, reverse the infix expression given in the problem.

2. Scan the expression from left to right.

3. Whenever the operands arrive, print them.

4. If the operator arrives and the stack is found to be empty, then simply push the operator into the stack.

5. If the incoming operator has higher precedence than the TOP of the stack, push the incoming operator into the stack.

6. If the incoming operator has the same precedence with a TOP of the stack, push the incoming operator into the stack.

7. If the incoming operator has lower precedence than the TOP of the stack, pop, and print the top of the stack. Test the incoming operator against
the top of the stack again and pop operator from the stack till it finds the operator of a lower precedence or same precedence.

8. If the incoming operator has the same precedence with the top of the stack and the incoming operator is ^, then pop the top of the stack till the
condition is true. If the condition is not true, push the operator.

9. When we reach the end of the expression, pop, and print all the operators from the top of the stack.
10. If the operator is ')', then push it into the stack.

11. If the operator is '(', then pop all the operators from the stack till it finds ) opening bracket in the stack.

12. If the top of the stack is ')', push the operator on the stack.

13. At the end, reverse the output.

You might also like