Evaluation of Postfix Expressions Using Stack [with C program]
belongs to collection: Data Structure programs using C and C++ (Sorting Programs)
All Answers
total answers (1)
belongs to collection: Data Structure programs using C and C++ (Sorting Programs)
total answers (1)
Algorithm
1) Add ) to postfix expression.
2) Read postfix expression Left to Right until ) encountered
3) If operand is encountered, push it onto Stack
[End If]
4) If operator is encountered, Pop two elements
i) A -> Top element
ii) B-> Next to Top element
iii) Evaluate B operator A
push B operator A onto Stack
5) Set result = pop
6) END
Let's see an example to better understand the algorithm:
Expression: 456*+
Result: 34
Evaluation of Postfix Expressions Using Stack
Output