Question 4 1 pts public interface Stack ( Returns the number of elements in the
ID: 3746622 • Letter: Q
Question
Question 4 1 pts public interface Stack ( Returns the number of elements in the stack. int sizeO 158 * Tests whether the stack is empty. 95/ boolean isEmpty); Inserts an element at the top of the stack. void push(Object e); * Returns, but does not remove, the element at the top of the stack, or null if the stack is empty Object top) * Removes and returns the top element from the stack, or null if the stack is empty. Object pop) Consider the following sequence of operations on a Stack that begins empty. Give the return value for each line. If it causes an error, then write ERROR.Explanation / Answer
pop() : B
as we inserted A ,B so if ew pop we will get the Last inserted element which is B
top() now have only 1 element which is A
pop() : we have A,C in statck so we will get C as it last inserted element
pop() now we have A only so we will get A
pop() : returns null as the stack is empty
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.