Solved

Assume That the CountIt and SumIt Methods in the Questions

Question 2

Multiple Choice

Assume that the countIt and sumIt methods in the questions below receive a parameter Node temp, which references the first Node in a linked list where Node is a class that consists of data instances int info and Node next and further assume that the int variables count and sum are initialized to 0.
-Which of the following methods could be used to sum all of the items in the linked list?


A) public int sumIt(Node temp) {
While (temp != null)
{
Sum += temp.info;
Temp = temp.next;
}
Return sum;
}
B) public int sumIt(Node temp) {
While (temp != null)
{
Sum += temp.info;
}
Return sum;
}
C) public int sumIt(Node temp) {
While (temp != null)
{
Sum++;
Temp = temp.next;
}
Return sum;
}
D) public int sumIt(Node temp) {
While (temp != head)
{
Sum += temp.info;
Temp = temp.next;
}
Return sum;
}
E) public int sumIt(Node temp) {
While (temp != null)
{
If (next != null) sum += temp.info;
Temp = temp.next;
}
Return sum;
}

Correct Answer:

verifed

Verified

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents