Prefix to Postfix Notation Algorithm and Flowchart

[4643 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 Prefix Notation to Postfix Notation.

Flowchart for converting Prefix to Postfix notation


Flowchart for converting Prefix to Postfix notation
Remove WaterMark from Above Flowchart

Algorithm for conversion of Prefix to Postfix notation:

Step 1: Start Step 2: Read the Prefix expression from right to left. 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 'operand1, operand2, operator'. Push the result into the stack. Step 5: Repeat steps 2-4 until the prefix expression ends. Step 6: Pop all the rest elements of the stack if any. Step 7: Stop

Let's take an example to understand *a+bc

  1. Reading from right to left, 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 cb+
  3. 'a' is then pushed into the stack.
  4. '*', is encountered and 'a' and string 'cb+' is popped and concatenated to give a string cb+a*
  5. Postfix form is obtained: cb+a*

You might be interested in this too.:

                 



Want to Learn How to write own Algorithm and Flowcharts



Want to test your logical skills in Algorithms?




Comments










Search Anything:

Sponsored Deals ends in



Interesting Technical Quizzes:

Search Tags

    Algorithm for converting Prefix to Postfix

    Flowchart for converting Prefix to Postfix

    Simple Explanation for prefix to Postfix