DEV Community

Bhavana
Bhavana

Posted on

ALGORITHM of Infix to Postfix Conversion Using Stack.

Postfix expression: The expression of a b op. when an operator is followed for every pair of operands.

Infix expression: The expression of the from a op b. when an operator is in between every pair of operands

ALGORITHM

step1: First we should scan the infix expression from left to right

step2: If scanned character is an operand ,we should get the output.

step3:Else,pop all the operators in the stack which are greater than or equal to in precedence than that of the scanned operator to the stack

step4: If the scanned character is an ’ ( ', push it to the stack.

step5 : If the scanned character is an ‘)’,pop the stack an output it until it is encountered, and discard both the parenthesis.

step 6: Repeat steps 2-6 until infix expression is scanned.

step7: print the output

step 8: pop and output from the stack until it is not empty

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay