Sunday 13 October 2013

Expression Trees

Step 1 : Convert the given expression to postfix form
Step 2 : Read one symbol at a time from the postfix expression
Step 3 : Check whether the symbol is an operator or operand.
(i)If it is an operand,create a one node tree and push a pointer on the stack.
(ii)If it is an operator,pop two pointers from the stack namely T1 and T2 and form a new tree with Root as operator and T2 as left child and T1 as right child.Push the pointer to this new tree on to the stack.
Step 4 : Repeat the Steps till the end of the expression.

No comments:

Post a Comment