top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we evaluate the infix expression with stack in one pass?

+1 vote
881 views

Can we evaluate the infix expression with stack in one pass? Sample C/C++ code would be helpful...

posted Mar 18, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Evaluate the infix expression with stack in one pass

Algorithm
Input:An arithmetic expression P in postfix notation;
1. scan P left to right; if character is operand push in stack.
2. else if character is operator
i. while the top of the stack is not of smaller precedence than this character.
ii. pop from stack.
iii. store let first operand operator second operand on the stack and go to 2.
3. pop operators till operator stack is not empty.
4. pop top 2 operands and push first operand operator second operand on the stack.
5. exit.

answer Mar 19, 2016 by Ajay Kumar
You provided postfix notation solution but the question is for the infix notation.
...