CSE205 - Quiz 9 Linked List

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

For the following question, 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. Assume Node temp references the last element of the linked list. Which of the following conditions is true about temp?

(temp.next == null)

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

It is fixed in size (static)

For the following question, 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;

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 the result to the linked list of the following instructions? Assume that newNode is a Node, already constructed. newNode.data = 1; newNode.next = head.next; head.next = newNode;

The value 1 is inserted into the linked list after 20 and before 11

Queues and Stacks can be implemented using either arrays or linked lists.

True

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

class Node { int data; Node next; }

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

Assume that the countIt method receives 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 variable count is initialized to 0. 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 that the method sumIt 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 is initialized to 0. Which of the following methods could be used to sum all of the items in the linked list?

public int sumIt(Node temp) { while (temp != null) { sum += temp.info; temp = temp.next; } return sum; }

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;


Ensembles d'études connexes

Milady Standard Foundations Ch. 1

View Set

Managerial Accounting Ch. 23 & 25

View Set

Ch.7 Evaluating Employee Performance

View Set

Understanding Business Chapter 6

View Set

Practical 1 Anatomical Terms Worksheet

View Set

Pathophysiology Chapter 14 - Pain, Temperature, Sleep, and Sensory Function

View Set

Adding Fractions with Different Denominators

View Set

The Women's Social and Political Union 1903-1914

View Set