Monday, 20 November 2017

Value of a Postfix Expression

Evaluation of a Postfix Expression



Evaluation of a Postfix Expression using Stack data structure.

We can use the following steps...

Step 1: Read all the symbols one by one from left to right in the given Postfix Expression.

Step 2: If the symbol is an operand, then push it onto the stack.

Step 3: If the symbol is an operator ( ✖ )

3.1 : Pop the two top symbols of the stack , where A is top-element and B is the next to top element.

3.2 : Evaluate B ( ✖ ) A

3.3 : Push result of 3.2 back on to the Stack.

Step 4: Perform a pop operation and display the popped value as final result.

value = Stack[top]; and printf the value.

Step 5: EXIT


Example

Consider the following Expression...


C program for evaluation of a postfix expression

# include <stdio.h>
# include <conio.h>
# include <string.h>
# define MAX 100

Share this

0 Comment to "Value of a Postfix Expression"

Post a Comment