in DS
1,711 views
2 votes
2 votes
If we have to construct the expression tree from this expression (3 + ((5+9)*2)) then what will be the order of push and pop operation on a stack ?Explain what to do with each operator and operand along the way of push and pop operation
in DS
1.7k views

4 Comments

@sekhar .. I had forgotten one more thing to mention there in 3rd step -- after making left and right child .. now we need to push that node(parent node) containing operator as data part of node into the stack.
0
0

its okay i got it .yes

0
0

Is it any rule that first poped node become right child of new node and second popped node become left child of new node.

I think it depend upon the the operater associativity who cause two pop from stack.

If incomming operator is left associativity then first poped node become right child of new node and second popped node become left child of new node.

If incomming operator is right associativity then first poped node become left child of new node and second popped node become right child of new node.

let me know am i correct?

0
0

1 Answer

3 votes
3 votes

this is basic idea, if we want to implement it we can modify accordingly

Related questions