I am doing some stack exercises and just want to make sure I havethe correct ans
ID: 3618900 • Letter: I
Question
I am doing some stack exercises and just want to make sure I havethe correct answers. Assume StackType is sent to int andSTACK_CAPACITY is set to 5. Give the values of myTop and thecontents of the array referred to by myArray in the stack s afterthe code segment is executed or indictate why an error occurs.1.
Stack s;
s.push(10);
s.push(22);
s.push(37);
s.pop();
s.pop();
This answer I put 10[0]
2.
Stack s;
s.push(10);
s.push(9);
s.push(8);
while(!s.empty())
s.pop();
This answer I put cannot be done because it goes empty and thenremoves a s.pop
3.
Stack s;
for (int i = 1; i <= 6; i++)
s.push(10*i);
Cannot be done because I is multiplied by 10 and the highest it canbe is 6
4.
Stack s;
s.push(11);
i = s.top();
s.pop();
This answer I put 3[0]
If these are wrong can someone explain to me what I need to put inhere
Explanation / Answer
please rate - thanks I am doing some stack exercises and just want to make sure I havethe correct answers. Assume StackType is sent to int andSTACK_CAPACITY is set to 5. Give the values of myTop and the contents of the array referred to bymyArray in the stack s after the code segment is executed or indictate whyan 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()) notempty noempty 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 thenremoves a s.pop incorrect see above 3. Stack s; for (int i = 1; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.