Determine the resulting stack which was empty at the start w

Determine the resulting stack, which was empty at the start while showing all steps: s - push(5); s - push(6); right = s.pop(); left = s.pop(); s - push(left - right); s - push(4); s - push(3); right = s.pop(); left = s.pop(); s - push(left * right); left = s.pop(); right = s.pop(); s - push(left - right);

Solution

let stack,s which is empty in start
push=insert element at the top of the stack
pop=remove element from the top of the stack

steps Result
s.push(5); s= 5
s.push(6); s=6,5
right=s.pop(); right=6,s=5
left=s.pop(); left=5,s is empty   
s.push(left - right); s=-1
s.push(4); s=4,-1
s.push(3); s=3,4,-1
right=s.pop(); right=3,s=4,-1
left=s.pop(); left=4,s=-1
s.push(left*right); s=12,-1
left=s.pop(); left=12,s=-1
right=s.pop(); right=-1,s is empty
s.push(left - right); s=13


Final answer:Resulting stack will have only one value i.e 13.

Please let me know in case of any question,thanks.

 Determine the resulting stack, which was empty at the start while showing all steps: s - push(5); s - push(6); right = s.pop(); left = s.pop(); s - push(left -

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site