Sie sind auf Seite 1von 8

Chapter 16: Linked Lists

TRUE/FALSE
1. Linked lists allow you to overcome the size limitations of an array data type.
ANS: T

PTS: 1

REF: 1032

2. Memory for the components of an array does not need to be contiguous.


ANS: F

PTS: 1

REF: 1032

3. You can use the pointer head of a linked list to traverse the list.
ANS: F

PTS: 1

REF: 1036

4. In a linked list, if a new item is always inserted at the beginning or at the end of the list and the data
read is unsorted, the linked list will be unsorted.
ANS: T

PTS: 1

REF: 1040

5. When you build a linked list in the backward manner, a new node is always inserted at the end of the
linked list.
ANS: F

PTS: 1

REF: 1040

6. You deallocate the memory for a linked list by calling the operator clear.
ANS: F

PTS: 1

REF: 1052

7. The length of a linked list is the number of nodes in the list.


ANS: T

PTS: 1

REF: 1053

8. It is not possible to create an ordered linked list.


ANS: F

PTS: 1

REF: 1066

9. A linked list is a random access data structure.


ANS: F

PTS: 1

REF: 1058

10. A doubly linked list can be traversed in either direction.


ANS: T

PTS: 1

REF: 1080

MULTIPLE CHOICE
1. Data can be organized and processed sequentially using an array called a(n) ____ list.
a. linked
c. sequential
b. ordered
d. ascending

ANS: C

PTS: 1

REF: 1032

2. A linked list is a collection of components called ____.


a. elements
c. members
b. nodes
d. pointers
ANS: B

PTS: 1

REF: 1032

3. In a linked list, the address of the first node in the list is stored in a separate location, called the ____
or first.
a. head
c. front
b. pointer
d. top
ANS: A

PTS: 1

REF: 1032

4. In a linked list, the order of the nodes is determined by the address, called the ____, stored in each
node.
a. head
c. link
b. tail
d. first
ANS: C

PTS: 1

REF: 1032

5. Every node (except of the last node) in a singly linked list contains ____.
a. the next node
b. no address information
c. the address of the next node
d. the address of the previous node
ANS: C

PTS: 1

REF: 1032

6. The link field of the last node of a linked list is ____.


a. NULL
c. n-1
1
b.
d. n
ANS: A

PTS: 1

REF: 1032

7. Because each node of a linked list has two components, we need to declare each node as a(n) ____.
a. reference and string
c. index and element
b. int and object
d. class or struct
ANS: D

PTS: 1

REF: 1033

8. Each node of a singly linked list has two components: ____ and ____.
a. info, head
c. back, head
b. link, back
d. info, link
ANS: D

PTS: 1

REF: 1034

9. Suppose that the pointer head points to the first node in the list, and the link of the last node is NULL.
The first node of the linked list contains the address of the ____ node.
a. head
c. second
b. first
d. tail
ANS: C

PTS: 1

10. What is the purpose of the following code?

REF: 1036

current = head;
while (current != NULL)
{
//Process current
current = current->link;
}
a. Insertion of a node
b. Selection of a node
ANS: C

PTS: 1

c. Traversal of a linked list


d. Creation of a new list
REF: 1036

struct nodeType
{
int info;
nodeType *link;
};
nodeType *head, *p, *q, *newNode;
newNode = new nodeType;
11. Consider the accompanying code. What is the effect of the following statement?
newNode->info = 50;
a.
b.
c.
d.

Stores 50 in the info field of the newNode


Creates a new node
Places the node at location 50
Cannot be determined from this code

ANS: A

PTS: 1

REF: 1038

12. When building a linked list in the ____ manner, a new node is always inserted at the end of the linked
list.
a. backward
c. traversal
b. forward
d. random
ANS: B

PTS: 1

REF: 1040

13. How many pointers are needed to build a linked list in a backward manner?
a. One
c. Three
b. Two
d. Four
ANS: B

PTS: 1

REF: 1044

14. Which of the following is a basic operation on singly linked lists?


a. Retrieve the data of an arbitrary node.
b. Swap the head and the last nodes.
c. Determine whether the list is full.
d. Make a copy of the linked list.
ANS: D

PTS: 1

REF: 1045

15. What is the output of the following program segment? (The class unorderedLinkedList is as
defined in the book.)
unorderedLinkedList<int> list;
list.insertFirst(6);
list.insertLast(5);
list.insertFirst(4);
list.insertFirst(8);
list.insertLast(10);
list.deleteNode(4);
list.insertFirst(1);
list.print();
a. 1 6 5 8 10
b. 1 6 8 10 5
ANS: C

c. 1 8 6 5 10
d. 1 8 10 6 5
PTS: 1

REF: 1046

16. The ____ deallocates the memory occupied by the nodes of a list when the class object goes out of
scope.
a. constructor
c. head pointer
b. destructor
d. tail pointer
ANS: B

PTS: 1

REF: 1056

17. The steps involved in inserting a new item at the beginning of an unordered linked list are ____.
a. 1. Create a new node.
2. Insert the node before first.
3. Increment the counter by 1.
b. 1. Create a new node.
2. Store the new item in the new node.
3. Insert the node before first.
4. Increment the counter by 1.
c. 1. Create a new node.
2. Store the new item in the new node.
3. Insert the node before first.
d. 1. Create a new node.
2. Store the new item in the new node.
3. Insert the node before first.
4. Decrement the counter by 1.
ANS: B

PTS: 1

REF: 1059

18. Every node in a doubly linked list has two pointers: ____ and ____.
a. previous; next
c. current; next
b. back; next
d. previous; current
ANS: B

PTS: 1

REF: 1082

19. Which of the following correctly initializes a doubly linked list in the default constructor?
a. head = NULL;
back = NULL;
b. head = 0;
back = 0;

count = 0;
c. first = 0;
last = 0;
d. first = NULL;
last = NULL;
count = 0;
ANS: D

PTS: 1

REF: 1083

template <class Type>


____ doublyLinkedList<Type>::isEmptyList() const
{
return (first == NULL);
}
20. Consider the accompanying statements. The operation returns true if the list is empty; otherwise, it
returns false. The missing code is ____.
a. protected
c. void
int
b.
d. bool
ANS: D

PTS: 1

REF: 1083

21. Consider the accompanying statements. The list is empty if the pointer first is ____.
a. NULL
c. last
b. 0
d. next
ANS: A

PTS: 1

REF: 1083

22. Consider the following code, which deletes all the nodes in a linked list.
void doublyLinkedList<Type>::destroy()
{
nodeType<Type> *temp; //pointer to delete the node
while (first != NULL)
{
temp = first;
first = first->next;
____
}
last = NULL;
count = 0;
}
Which of the following is the missing statement?
a. delete first;
c. destroy temp;
b. delete temp;
d. clear temp;
ANS: B

PTS: 1

REF: 1083

23. Consider the following code:


template <class Type>
int doublyLinkedList<Type>::length() const
{
____
}

The statement that provides the length of the linked list is ____.
a. cout <<< count;
c. return count;
destroy();
b.
d. return next;
ANS: C

PTS: 1

REF: 1084

24. Which of the following statements appears in the insert function of a doubly linked list?
a. current++;
c. newNode++;
trailCurrent++;
b.
d. count++;
ANS: D

PTS: 1

REF: 1087

25. The deleteNode operation (if the item to be deleted is in a doubly linked list) requires the
adjustment of ____ pointer(s) in certain nodes.
a. one
c. three
b. two
d. four
ANS: B

PTS: 1

REF: 1088

COMPLETION
1. In a linked list, the link component of each node is a(n) ____________________.
ANS: pointer
PTS: 1

REF: 1033

2. Each node of a linked list must store the data as well as the ____________________ for the next node
in the list.
ANS: address
PTS: 1

REF: 1046

3. In C++, the dereferencing operator is represented by the ____________________ symbol.


ANS: *
PTS: 1

REF: 1047

4. A(n) ____________________ is an object that produces each element of a container, such as a linked
list, one element at a time.
ANS: iterator
PTS: 1

REF: 1047

5. The ____________________ operator advances the iterator to the next node in the linked list.
ANS: increment
PTS: 1

REF: 1047

6. In a linked list, the ____________________ operator returns the info of the current node.
ANS: dereferencing
PTS: 1

REF: 1047

7. For classes that include pointer data members, the assignment operator must be explicitly
____________________.
ANS: overloaded
PTS: 1

REF: 1052

8. If a formal parameter is a value parameter, the ____________________ constructor provides the


formal parameter with its own copy of the data.
ANS: copy
PTS: 1

REF: 1056

9. The ____________________ constructor executes when an object is declared and initialized using
another object.
ANS: copy
PTS: 1

REF: 1056

10. The ____________________ constructor can make an identical copy of a linked list.
ANS: copy
PTS: 1

REF: 1056

11. A linked list must be searched ____________________, starting from the first node.
ANS: sequentially
PTS: 1

REF: 1058

12. The nodes of a standard ordered list (as constructed in the text) are in ____________________ order.
ANS: ascending
PTS: 1

REF: 1077

13. A(n) ____________________ linked list is a linked list in which every node has a next pointer and a
back pointer.
ANS: doubly
PTS: 1

REF: 1080

14. In a circular linked list with more than one node, it is convenient to make the pointer first point to
the ____________________ node of the list.
ANS: last
PTS: 1

REF: 1091

15. A linked list in which the last node points to the first node is called a(n) ____________________
linked list.
ANS: circular
PTS: 1

REF: 1091

Das könnte Ihnen auch gefallen