Suppose that the method below is one of the methods in a LinkedList class. Assum
ID: 3781491 • Letter: S
Question
Suppose that the method below is one of the methods in a LinkedList class. Assume that the list has a dummy header node and that the list is not empty. The method returns which of the following?
public int operation()
{
Node current = first.getNext();
int value = current.getInfo();
while (current != null)
{
if(current.getInfo() < value)
value = current.getInfo();
current = current.getNext();
}
return value;
}
a. The sum of all list elements
b. The smallest element in the list
c. The greatest element in the list
d. The number of elements in the list
Explanation / Answer
answer is option b.
i.e. The smallest element in the list.
in given code it checks for smallest element and gives that value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.