Sunday, December 17, 2023

Infix to prefix conversion

 ALGORITHM:

STEP 1:

Add " ( " at the beginning of the infix expression and then reverse.

STEP 2:

Push " ) " on to the stack.

STEP 3:

Scan every character and repeat step 4 to step 7 until " ( " is encountered.

STEP 4:

If input is operand add in the output.

STEP 5:

If input is " ) " push into the stack.

STEP 6:

If input is "(" pop all the operators from the stack and add in the output one by one until ")" is popped.

STEP 7:

If input is operator pop all the stack which is higher precedence than input operator .Push input operator into the stack.

STEP 8:

Reverse the output


EXAMPLE:



No comments:

Post a Comment

Complete Works of Swami Vivekananda [Volume 8,Page - 2069]

  Complete Works of Swami Vivekananda [ Volume 8, Page - 2069] Jesus Christ was God — the Personal God become man. He has manifested Himsel...