Introduction to C++ Programming, Y. Daniel Liang
Chapter 16 Linked Lists, Stacks, and Queues
Section 16.2 Nodes
1
If a pointer p does not point to anything, assign ________ to p.
A.
null
B.
Null
C.
NULL
D.
0
2
If a list is empty, which of following statements are true?
A.
head is NULL.
B.
tail is NULL.
C.
head = tail.
D.
head < tail.
3
Which of the following two versions of the class declarations is correct?
Version I:
     class A
     {
     public:
       A()
       {
       }
    
     private:
       A* a;
       int i;
     };
Version II:
     class A
     {
     public:
       A()
       {
       }
    
     private:
       A a;
       int i;
     };
A.
Both versions are correct.
B.
Version I is correct.
C.
Version II is correct.
D.
Both versions are wrong.
4
What is the value of tail->next?
A.
0
B.
NULL
C.
head
D.
tail
Section 16.3 The LinkedList Class
5
In the implementation of LinkedList.h, which of the following are true?
A.
LinkedList has a size property.
B.
LinkedList has the properties named head and tail to point to the nodes in a linked list.
C.
If a linked list contains one element, head points to the node and tail is NULL.
D.
tail.next is always NULL.
6
In the implementation of MyLinkedList.h, Which of the following statements are to insert a string s to the head of the list?
A.
list.addFirst(s);
B.
list.add(s);
C.
list.add(0, s);
D.
list.add(1, s);
E.
list.insert(s);
7
In the implementation of LinkedList.h, Which of the following statements are to append a string s to the end of the list?
A.
list.addFirst(s);
B.
list.add(s);
C.
list.add(0, s);
D.
list.add(1, s);
E.
list.insert(s);
8
In the implementation of LinkedList.h, Which of the following statements are to remove the first element from the list?
A.
list.removeFirst(s);
B.
list.removeFirst();
C.
list.remove(0);
D.
list.removeAt(0);
9
In the implementation of LinkedList.h, Which of the following statements are to remove the last element from the list?
A.
list.removeLast(s);
B.
list.removeLast();
C.
list.removeAt(list.getSize() - 1);
D.
list.remove(list.getSize() - 1);
10
When a new node is inserted to the head of a linked list, will the head pointer and the tail pointer be changed?
A.
If the list is empty before the insertion, both head and tail will change.
B.
If the list is not empty before the insertion, head will change.
C.
head will always change, but tail will never change.
D.
both head and tail will change.
11
When a new node is inserted to the end of a linked list, will the head pointer and the tail pointer be changed?
A.
If the list is empty before the insertion, both head and tail will change.
B.
If the list is not empty before the insertion, tail will change.
C.
head will always change, but tail will never change.
D.
both head and tail will change.
12
If the number of elements in the program is fixed, what data structure should you use?
A.
vector
B.
linked list
C.
array
D.
stack
13
If you have to add or delete the elements anywhere in a list, what data structure should you use?
A.
vector
B.
linked list
C.
array
D.
stack
14
Which data structure is appropriate to store customers waiting in line at a clinic for a flu shots?
A.
Stack
B.
Queue
C.
Array
D.
Linked List
15
Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants?
A.
Stack
B.
Queue
C.
Array
D.
Linked List