DEV Community

Cover image for Infix to Postfix Conversion using Stack
hebaShakeel
hebaShakeel

Posted on

1 1

Infix to Postfix Conversion using Stack

  1. Print the operands as they arrive.

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

  3. If incoming symbol is '(', push it onto stack.

  4. If incoming symbol is ')', pop the stack and print the operators until the left parentheses 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. Then test the incoming operator against the new top of the stack.

  7. If the incoming operator has equal precedence with the top of the operator , use Associativity rule.

  8. If associativity is Left -> Right (^), then pop and print the top of the stack and then push the incoming operator.

  9. If the associativity is Right -> Left (+,-,*,/) , then push the incoming operator.

  10. At the end of the expression, pop and print all operators of stack.

Your conversion should be ready.
Thank You!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay