Binary Tree – Post Order + * a • Post Order • ab*c+ c b
Infix to Post Fix Conversion using Stacks Order of precedence for operators * / + If an operator is pushed onto stack and the operator below it is of higher or equal precedence remove bottom item from stack • If an operator is pushed onto stack and the operator below it is of a lower precedence operators remain on stack • •
Infix to Post Fix Conversion using Stacks • • 4 + 2 * 5 (Infix) 4 2 5 * + (RPN) * + Stack 42 5 * + String
Infix to Post Fix Conversion using Stacks • 4 * 2 + 5 (Infix) • 4 2 * 5+ (RPN) + * + Stack 42*5 + String
Infix to Post Fix Conversion using Stacks • 4 - 2 + 5 (Infix) • 4 2 – 5 + (RPN) + + Stack 42 - 5 + String
Infix to Post Fix Conversion using Stacks • 4 / 2 * 5 (Infix) • 4 2 / 5 * (RPN) * / * Stack 42/ 5 * String
Evaluate RPN in Stack • ab*c+ • (a*b)+c (Infix) • • Push operands When reach operator evaluate previous 2 operands Pop 2 operands Push evaluation a b a (a*b) c (a*b)+c