Quiz 9- Linked List

¡Supera tus tareas y exámenes ahora con Quizwiz!

Assume Node temp references the last element of the linked list. Which of the following conditions is true about temp?

(temp.next == null)

For next questions , assume that a linked list consists of Node objects, where Node has two instance data, int info and Node next. The linked list stores in the info data, 20, 11, 13, 19, 12, 14 in that order. Assume that Node head references the first item in the list list. What will be returned by return head.next.next.next.info; ?

19, The variable head references the first item, which stores 20, head.next references the second item, which stores 11, head.next.next references the third item, which stores 13, and head.next.next.next references the fourth item, which stores 19.

For next question, assume that a linked list consists of Node objects, where Node has two instance data, int info and Node next. The linked list stores in the info data, 20, 11, 13, 19, 12, 14 in that order. Assume that Node head references the first item in the list list. What is returned by return head.info; ?

20, the variable head references the first item, and so head.data is the instance data info of the first item which stores 20.

For following questions, assume that a linked list is implemented using the Node class where a Node contains instance data of int info; and Node next; where next references the next Node in the linked list. Also assume that head references the first Node in the list. Which of the following instructions would create an initially empty linked list?

Node head = null; The initial linked list will be empty, and so head should be null to indicate that there are no Nodes in the list yet. The answer in b is syntactically invalid, and the answers in a and d may be invalid depending on what parameter(s) the Node constructor expects, but in any event, the answers in a and d will create a Node, and therefore the initial list will not be empty.

The advantage of creating a BookList using a linked list instead of using an array is that the linked list

is dynamic and so can be any size needed

Which of the following criticisms of an array is applicable to a Java array?

it is a fixed in size (static)

A linked list that stores int values would be comprised of a group of Nodes. We might define the Node by

public class Node{ int data; Node next; }

Which of the following methods could be used to count the number of items in the linked list?

public int countIt(Node temp){ while(temp != null){ count++; temp = temp.next; } return count; }

Assume Node temp is currently set equal to head. Which of the following while loops could be used to iterate through each element of a linked list?

while (temp != null) temp = temp.next();


Conjuntos de estudio relacionados

Medical Assistant Anatomy and Physiology

View Set

Unit 4 Study Guide- Essential Questions

View Set

Old Testament Survey Ch. 24-34 Reading Log 3 McClean

View Set

Chapter 3: Psychosocial Theories and Therapy

View Set

Unit 4 Review: Triumph Of Industry; Labor Movement; Cities, Immigration And Farmers

View Set