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:
Verified
Q1: Assume that the countIt and sumIt methods
Q3: What is the result to the linked
Q4: Which of the following criticisms of an
Q5: For the questions below, assume that a
Q6: For the questions below, assume that a
Q7: For the questions below, assume that a
Q8: Abstract Data Types have which of the
Q9: A collection in the items stored there
Q10: What will the statement head.next.next = head.next.next.next;
Q38: A linked list that stores int values
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents