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:
Verified
Q31: In a linked list in Java
A) the
Q32: Example Code Ch 13-3
Assume that countIt and
Q33: Example Code Ch 13-2
Assume that a linked
Q34: Example Code Ch 13-2
Assume that a linked
Q35: To simulate people waiting in a line,
Q37: Example Code Ch 13-4
Assume that a linked
Q38: A linked list that stores int values
Q39: One operation that we might want to
Q40: The advantage of creating a BookList for
Q41: Two abstract data types are the ordered
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