Evaluate the following postfix expression: 6 4 + 3 10 * 2 2 2 - + * +
What is the highest number of elements on our stack at any one time?
can you please explain the answer for me ?
6 4 + 3 10 * 2 2 2 - + * + -------------------------------- stack: [] push 6 stack: [6] push 4 stack: [6 4] pop, 6 and 4, push 6+4 = 10 stack: [10] push 3 stack: [10 3] push 10 stack: [10 3 10] pop, 3 and 10, push 3*10 = 30 stack: [10 30] push 2 stack: [10 30 2] push 2 stack: [10 30 2 2] push 2 stack: [10 30 2 2 2] pop, 2 and 2, push 2-2 = 0 stack: [10 30 2 0] pop, 2 and 0, push 2+0 = 2 stack: [10 30 2] pop, 30 and 2, push 30*2 = 60 stack: [10 60] pop, 10 and 60, push 10+60 = 70 stack: [70] value of this expression is 70 and we can see that maximum size of stack is 5
Get Answers For Free
Most questions answered within 1 hours.