What will be the result if a postfix notation 2 3 6 5 4 wi

What will be the result if a postfix notation 2 3 6 5 - 4 + will be evaluated? What will be the result if a postfix notation 2 3 4 6 5 + + will be evaluated?

Solution

In this question , Initially we will put operands into stacks and as soon as operator comes, we take out two operands and apply operator and put the result again into stack.

a) Initially, 2,3,6,5 are into stack then \'-\' comes

this calculates 6-5=1

and 1 is put into stack. Next 4 is inserted into stack. So the stack becomes as 2,3,1,4

Now \'+\' comes which adds 1+4 =5 and 5 is put into stack. So, the Stack contents becomes as

2,3,5 . Now, \'*\' comes which multiplies 3*5=15 and 15 is put into stack with 2. At the end \'+\' comes

so, 2+15=17 is the result returned.

b) Similar to 1st question Stack becomes 2,3,4,6,5 now the operator comes \'+\'

which adds 6+5=11 and 11 is put into stack making stack content 2,3,4,11. Next operator \'+\' comes which makes 11+4=15 and stack content as 2,3,15 and next operator is \'*\' which gives us 3*15=45

and stack content as 2,45 and now the last operator \'+\' comes which gives us 2+45=47 as our result.

 What will be the result if a postfix notation 2 3 6 5 - 4 + will be evaluated? What will be the result if a postfix notation 2 3 4 6 5 + + will be evaluated?So

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site