Beruflich Dokumente
Kultur Dokumente
TRUE/FALSE
1. Linked lists allow you to overcome the size limitations of an array data type.
ANS: T
PTS: 1
REF: 1032
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
PTS: 1
REF: 1053
PTS: 1
REF: 1066
PTS: 1
REF: 1058
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
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
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
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
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.
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
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
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
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
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
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