Postfix to Prefix notation Algorithm and Flowchart

[846 views]


Prefix notation is a type of notation in which arithmetic expressions are written in a manner such that the operands appear after their operators.

Postfix notation is a type of notation in which arithmetic expressions are written in a manner such that the operands appear before their operators.

Let's see how to convert Postfix Notation to Prefix Notation.

Flowchart for Postfix to Prefix Conversion

Flowchart for Postfix to Prefix Conversion

Algorithm for Postfix to Prefix Conversion:

Step 1: Start Step 2: Read the Postfix expression from left to right. Step 3: If the scanned character is an operand, then push it onto the Stack. Step 4: If the scanned character is an operator, pop two operands from the stack and concatenate them in order of 'operator, operand2, operand1'. Push the result into the stack. Step 5: Repeat steps 2-4 until the postfix expression ends. Step 6: Pop all the rest elements of the stack if any. Step 7: Stop

Let's take an example to understand cb+a*,

  1. Reading from left to right, we scan the operands 'c' 'b' respectively and push it into the the stack.
  2. '+' is scanned and operands 'c', 'b' are popped and concatenated in form of +bc
  3. 'a' is then pushed into the stack.
  4. '*', is encountered and 'a' and string '+bc' is popped and concatenated to give a string *a+bc
  5. Postfix form is obtained: *a+bc

You might be interested in this too.:

        

Algorithm Logic Test

Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once. 



Need any help in Programming? Chat with Us

Comments



Online Compiler
Search
Algorithm Quiz

Only 5% Users were able to score above 75% in this Quiz. Can You Crack this?

Deals Ends in





Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Algorithm for Postfix to Prefix notation

    Flowchart for Postfix to Prefix notation