What does the following function do? [code] public Object some_func()throws emptyStackException { if(isEmpty()) throw new emptyStackException

thanhthao

New member
What does the following function do?
Code:
public Object some_func()throws emptyStackException
{
	if(isEmpty())
		throw new emptyStackException("underflow");
	return first.getEle();
}
A. pop
B. delete the top-of-the-stack element
C. retrieve the top-of-the-stack element
D. push operation
 
Answer: C
Explanation: This code is only retrieving the top element, note that it is not equivalent to pop operation as you are not setting the ‘next’ pointer point to the next node in sequence.
 

Tìm kiếm

Back
Top