What does the following function do?
public T doSomething() throws EmptyCollectionException{
if (isEmpty())
throw new EmptyCollectionException(“Stack”);
T result = top.getElement();
top = top.getNext();
count--;
return result;
}
Select one:
a. isEmpty()
b. Push()
c. Pop()
d. Peek()
c. Pop() Explanation: ------------- T result = top.getElement(); this gets the top element and then top = top.getNext(); removes the top element of the collection count--; decreases the size of collection return result; returns the top element which was removed. this operation is clearly pop operation.
Get Answers For Free
Most questions answered within 1 hours.