Solved

Example Code Ch 13-3

Question 36

Multiple Choice

Example Code Ch 13-3
Assume that countIt and sumIt methods 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.
-Refer to Example Code Ch 13-3: Which of the following methods could be used to sum the number of 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

Unlock this answer now
Get Access to more Verified Answers free of charge

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