jimJohnson 2 Posting Whiz

I am doing some stack exercises and just want to make sure I have the correct answers. Assume StackType is sent to int and STACK_CAPACITY is set to 5. Give
the values of myTop and the contents of the array referred to by myArray
in the stack s after the code segment is executed or indictate why an
error occurs.

1.

Stack s;

s.push(10); 10 -0

s.push(22); 22 - 1
10

s.push(37); 37 - 2
22
10

s.pop(); 22 - 1
10

s.pop(); `0 - 0

This answer I put 10[0] correct

2.

Stack s;

s.push(10); 10 - 0

s.push(9); 9 - 1
10

s.push(8); 8-2
9
10

while(!s.empty()) not empty no empty empty so exit loop
s.pop(); 9 - 1 so so
10 10 - 0 set empty

This answer I put cannot be done because it goes empty and then removes a s.pop incorrect see above

3.

Stack s;

for (int i = 1; i <= 6; i++)

s.push(10*i);
after loop
60 - 5
50
40
30
20
10

Cannot be done because I is multiplied by 10 and the
highest it can be is 6 cannot be done because capacity is 5, and this is 6 items in the stack

4.

Stack s;

s.push(11); 11 -0

i = s.top(); i=0

s.pop(); empty

This answer I put stack is empty
3[0]

If these are wrong can someone explain to me what I need to put in here