Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys I really need help with this because I do not understand how it works.

ID: 3576994 • Letter: H

Question

Hey guys I really need help with this because I do not understand how it works. If someone could explain to me what and why the answers are it would really help!

8. [20 points] Given a stack implementation with the following interface, complete the chart when the corresponding class Stack member functions are invoked. Assume the stack is initially public int size empty bool empty inta top void push inte e) int pop Function call Output Stack Contents (bottom top) size() pop() push (100) push (200) push (300) top() pop() top() empty 0 push (100) push (400) top() empty 0 pop() push (500)

Explanation / Answer

push() will push an element into the stack, and will return nothing.

pop() will remove the top element of the stack, and will return the same.

top() will not modify the stack, but will return the top element of the stack.

empty() will return true if the stack is empty, and false otherwise.

size() will return the number of elements in the stack.

Function Call Output Stack Content size() 0 - pop() -1 - push('100') - '100' push('200') - '100', '200' push('300') - '100', '200', '300' top() '300' '100', '200', '300' pop() '300' '100', '200' top() '200' '100', '200' empty() false '100', '200' push('100') - '100', '200', '100' push('400') - '100', '200', '100', '400' top() '400' '100', '200', '100', '400' empty() false '100', '200', '100', '400' pop() '400' '100', '200', '100' push('500') - '100', '200', '100', '500'