Prefix to Postfix conversion using stack – DSA Course – Playlist in C++ – Coding With Clicks

✅ Prefix to Postfix Conversion

💡 Rules:

  1. Scan the prefix expression right to left.
  2. If the token is an operand, push it to the stack.
  3. If the token is an operator, pop two operands from the stack.
  4. Combine as:
    <operand1> <operand2> <operator>
  5. Push the resulting string back to the stack.

🧠 Example:

Prefix: + A * B C

Steps:

  • Read C → push
  • Read B → push
  • Read * → B C * → push
  • Read A → push
  • Read + → A B C * + → push

Postfix: A B C * +

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top