Convert Infix To Postfix Notation - Javatpoint
Convert Infix To Postfix Notation - Javatpoint
2. If the character is a digit, convert the character into int and push the integer into the stack.
Pop the elements from the stack twice obtaining two operands.
Here, we will use the stack data structure for the conversion of infix expression to prefix expression.
Whenever an operator will encounter, we push operator into the stack. If we encounter an operand,
then we append the operand to the expression.
2. If the stack is empty or contains a left parenthesis on top, push the incoming operator 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.
⇧ SCROLL TO TOP
https://www.javatpoint.com/convert-infix-to-postfix-notation 8/14
8/12/22, 10:51 PM Convert Infix to Postfix notation - javatpoint
K K
+ +
L + KL
- - K L+
M - K L+ M
* -* K L+ M
N -* KL+MN
+ + K L + M N*
K L + M N* -
( +( K L + M N *-
O +( KL+MN*-O
^ +(^ K L + M N* - O
P +(^ K L + M N* - O P
) + K L + M N* - O P ^
* +* K L + M N* - O P ^
W +* K L + M N* - O P ^ W
/ +/ K L + M N* - O P ^ W *
U +/ K L + M N* - O P ^W*U
/ +/ K L + M N* - O P ^W*U/
V +/ KL + MN*-OP^W*U/V
* +* KL+MN*-OP^W*U/V/
T +* KL+MN*-OP^W*U/V/T
⇧ SCROLL TO TOP
https://www.javatpoint.com/convert-infix-to-postfix-notation 9/14
8/12/22, 10:51 PM Convert Infix to Postfix notation - javatpoint
+ + KL+MN*-OP^W*U/V/T*
KL+MN*-OP^W*U/V/T*+
Q + KL+MN*-OP^W*U/V/T*Q
KL+MN*-OP^W*U/V/T*+Q+
The final postfix expression of infix expression(K + L - M*N + (O^P) * W/U/V * T + Q) is KL+MN*-
OP^W*U/V/T*+Q+.
← Prev Next →
Feedback
⇧ SCROLL TO TOP
https://www.javatpoint.com/convert-infix-to-postfix-notation 10/14