Select from following answers:- a b c * d + /
- a b c * d / +

- a b + c d * /
- a b c + d / *
- All Above
Step 1: First Character is Alphabet (i.e. 'a'). Display It in Postfix string. (Current Output in Postfix string: a)
Step 2: Second character is Operator(i.e. '+') and stack is empty, push '+' to stack. (Current Output in Postfix string: a)
Step 3: Third Character is Alphabet (i.e. 'b'). Display It in Postfix string. (Current Output in Postfix string: ab)
Step 4: Fourth character is Operator(i.e. '*') and stack has already '+' as the top element of the stack .But '+' has lower precedence than '*' so push '*' to stack(Stack status *+). (Current Output in Postfix string: ab)
Step 5: Fifth Character is Alphabet (i.e. 'c'). Display It in Postfix string. (Current Output in Postfix string: abc)
Step 6: Sixth character is Operator(i.e. '/') and stack has already '*+'. Since '*' has a higher precedence than '/', this will be poped out from stack and will be added to Postfix string. Since '/' has higher precedence that '+', hence it will be added to stack (Stack status /+). (Current Output in Postfix string: abc*)
Step 7: Seventh Character is Alphabet (i.e. 'd'). Display It in Postfix string. (Current Output in Postfix string: abc*d)
Step 8: Now all characters have been scanned so we must pop the remaining elements from the stack and add it to the Postfix string. So the final Postfix string will be abc*d/+
Show Correct Answer
Asked In: Many Interviews |
Alert Moderator