1) Recall that within theArrayBoundedStackthetopIndexvariable holds the index of theelementsarray where the current top of stack is stored. If a stack is empty, then itstopIndexvariableis:
a) -1
b) 0
c) 1
d) DEFCAP
e) None of above
8) 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?
a) 2
b) 3
c) 4
d) 5
e) None of above
1) a) -1 when stack is empty, then top is -1 2) d) 5 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.