Deck 15: Standard Library Containers and Iterators
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/33
Play
Full screen (f)
Deck 15: Standard Library Containers and Iterators
1
Which of the following containers is not considered a near container?
A) C-like arrays
B) vectors
C) strings
D) bitsets
A) C-like arrays
B) vectors
C) strings
D) bitsets
B
2
Which of the following is not a sequence container provided by the Standard Library?
A) vector
B) array
C) list
D) deque
A) vector
B) array
C) list
D) deque
B
3
Which category of iterators combines the capabilities of input and output iterators into one iterator?
A) Forward iterators.
B) Bidirectional iterators.
C) Random access iterators.
D) Input/output iterators.
A) Forward iterators.
B) Bidirectional iterators.
C) Random access iterators.
D) Input/output iterators.
A
4
The main difference between set and multiset is:
A) Their interface.
B) That one deals with keys only, and the other deals with key/value pairs.
C) Their efficiency.
D) How they handle duplicate keys.
A) Their interface.
B) That one deals with keys only, and the other deals with key/value pairs.
C) Their efficiency.
D) How they handle duplicate keys.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following is not a member function of all sequence containers?
A) front
B) back
C) push_front
D) push_back
A) front
B) back
C) push_front
D) push_back
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following is the correct hierarchy of iterator categories (weakest at the left)?
A) Input/output, forward, bidirectional, random access.
B) Random access, forward, bidirectional, input/output.
C) Bidirectional, forward, random access, input/output.
D) Input/output, bidirectional, forward, random access.
A) Input/output, forward, bidirectional, random access.
B) Random access, forward, bidirectional, input/output.
C) Bidirectional, forward, random access, input/output.
D) Input/output, bidirectional, forward, random access.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
7
The list sequence container does not:
A) Efficiently implement insert and delete operations anywhere in the list.
B) Use a doubly linked list.
C) Support bidirectional iterators.
D) Automatically sort inserted items.
A) Efficiently implement insert and delete operations anywhere in the list.
B) Use a doubly linked list.
C) Support bidirectional iterators.
D) Automatically sort inserted items.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following is not a member function of all sequence containers?
A) front
B) middle
C) back
D) pop_back
A) front
B) middle
C) back
D) pop_back
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following are mutating-sequence algorithms defined in the Standard Library?
A) copy
B) remove_if
C) find
D) Both (a) and (b).
A) copy
B) remove_if
C) find
D) Both (a) and (b).
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
10
Unlike a vector, a deque:
A) Provides efficient insertion and deletion only at its front.
B) Does not provide indexed access with the subscript operator.
C) Is not stored in contiguous memory.
D) Cannot store as many different data types.
A) Provides efficient insertion and deletion only at its front.
B) Does not provide indexed access with the subscript operator.
C) Is not stored in contiguous memory.
D) Cannot store as many different data types.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
11
Class deque provides:
A) Efficient indexed access to its elements.
B) The ability to add storage at either end of the deque.
C) Efficient insertion and deletion operations at the front and back of a deque.
D) All of the above.
A) Efficient indexed access to its elements.
B) The ability to add storage at either end of the deque.
C) Efficient insertion and deletion operations at the front and back of a deque.
D) All of the above.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
12
As of C++11, you can ask a vector or deque to return unneeded memory to the system by calling member function shrink_to_fit. This requests that the container reduce its capacity to the number of elements in the container. According to the C++ standard, implementations can ignore this request so that they can perform implementation-specific optimizations.
A) minimize_memory
B) shrink_to_fit
C) reduce_capacity
D) squeeze_to_size
A) minimize_memory
B) shrink_to_fit
C) reduce_capacity
D) squeeze_to_size
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
13
A Standard Library algorithm cannot:
A) Return an iterator.
B) Take two iterators as arguments to specify a range.
C) Access Standard Library members directly.
D) Be used with containers that support more powerful iterators than the minimum requirements for the algorithm.
A) Return an iterator.
B) Take two iterators as arguments to specify a range.
C) Access Standard Library members directly.
D) Be used with containers that support more powerful iterators than the minimum requirements for the algorithm.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
14
The erase member function of class vector cannot:
A) Specify an element to be removed from the vector.
B) Specify a value to be removed from the vector.
C) Specify a range of elements to be removed from the vector.
D) Be called by member function clear.
A) Specify an element to be removed from the vector.
B) Specify a value to be removed from the vector.
C) Specify a range of elements to be removed from the vector.
D) Be called by member function clear.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following applications would a deque not be well suited for?
A) Applications that require frequent insertions and deletions at the front of a container.
B) Applications that require frequent insertions and deletions in the middle of a container.
C) Applications that require frequent insertions and deletions at the back of a container.
D) Applications that require frequent insertions and deletions at the front and at the back of a container.
A) Applications that require frequent insertions and deletions at the front of a container.
B) Applications that require frequent insertions and deletions in the middle of a container.
C) Applications that require frequent insertions and deletions at the back of a container.
D) Applications that require frequent insertions and deletions at the front and at the back of a container.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following is not a key component of the Standard Library?
A) Containers.
B) Iterators.
C) Algorithms.
D) Pointers.
A) Containers.
B) Iterators.
C) Algorithms.
D) Pointers.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following statements is false?
A) C++14's global rbegin, rend, crbegin and crend functions are for iterating through a built-in array or a container from back to front.
B) Functions rbegin and rend return iterators that can be used to modify data, and rcbegin and rcend return const iterators that cannot be used to modify data.
C) Functions begin and end and their C++14 const and reverse versions may also receive container objects as arguments-each function calls the corresponding member function in its container argument.
D) When iterating using iterators, it's common for the loop-continuation condition to test whether the iterator has reached the end of the built-in array or the container. This technique is used by many Standard Library algorithms.
A) C++14's global rbegin, rend, crbegin and crend functions are for iterating through a built-in array or a container from back to front.
B) Functions rbegin and rend return iterators that can be used to modify data, and rcbegin and rcend return const iterators that cannot be used to modify data.
C) Functions begin and end and their C++14 const and reverse versions may also receive container objects as arguments-each function calls the corresponding member function in its container argument.
D) When iterating using iterators, it's common for the loop-continuation condition to test whether the iterator has reached the end of the built-in array or the container. This technique is used by many Standard Library algorithms.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
18
Iterators are similar to pointers because of the:
A) * and ++ operators.
B) -> operator.
C) begin and end functions.
D) & operator.
A) * and ++ operators.
B) -> operator.
C) begin and end functions.
D) & operator.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is a difference between vectors and arrays?
A) Access to any element using the [] operator.
B) Stored in contiguous blocks of memory.
C) The ability to change size dynamically.
D) Efficient direct access to any element.
A) Access to any element using the [] operator.
B) Stored in contiguous blocks of memory.
C) The ability to change size dynamically.
D) Efficient direct access to any element.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following is not an Standard Library container type?
A) Second-class containers.
B) Sequence containers.
C) Associative containers.
D) Container adapters.
A) Second-class containers.
B) Sequence containers.
C) Associative containers.
D) Container adapters.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
21
As of C++14, the argument to find (and other similar functions) can be of any type, provided that there are overloaded comparison operators that can compare values of the argument's type to values of the container's key type. If there are, no temporary objects will be created. This is known as ________ lookup.
A) homogenous
B) intergeneous
C) heterogenous
D) intrageneous
A) homogenous
B) intergeneous
C) heterogenous
D) intrageneous
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
22
If a program attempts to insert a duplicate key into a set:
A) An exception is thrown.
B) The set will contain multiple copies of that key.
C) A compile error will occur.
D) The duplicate key will be ignored.
A) An exception is thrown.
B) The set will contain multiple copies of that key.
C) A compile error will occur.
D) The duplicate key will be ignored.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following statements is true of a priority_queue?
A) It does not allow insertions in sorted order.
B) Each of its common operations is implemented as an inline function.
C) A bucket sort is usually associated with it.
D) It must be implemented as a deque.
A) It does not allow insertions in sorted order.
B) Each of its common operations is implemented as an inline function.
C) A bucket sort is usually associated with it.
D) It must be implemented as a deque.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
24
Part of the functionality of member function _________ can be performed by member function lower_bound.
A) equal_range
B) find
C) count
D) insert
A) equal_range
B) find
C) count
D) insert
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following is a not a member function of queue?
A) enqueue
B) pop
C) empty
D) size
A) enqueue
B) pop
C) empty
D) size
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
26
The multiset associative container does not:
A) Need a header file to be used.
B) Use its comparator function object to determine the order of its data.
C) Arrange its data in ascending order by default.
D) Permit random access to its keys.
A) Need a header file to be used.
B) Use its comparator function object to determine the order of its data.
C) Arrange its data in ascending order by default.
D) Permit random access to its keys.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
27
Select the false statement. Container adapters:
A) Do not provide the actual data structure implementation for elements to be stored.
B) Have their data stored by underlying data structures.
C) Can push and pop elements.
D) Have limited iterator support.
A) Do not provide the actual data structure implementation for elements to be stored.
B) Have their data stored by underlying data structures.
C) Can push and pop elements.
D) Have limited iterator support.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following bitset member functions cannot be called with an empty argument list?
A) reset
B) test
C) size
D) none
A) reset
B) test
C) size
D) none
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
29
Data loss could occur if the contents of a __________ were placed into any of the other three associative container types.
A) multiset.
B) set.
C) multimap.
D) map.
A) multiset.
B) set.
C) multimap.
D) map.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
30
The expression std::multimap>::value_type(15, 2.7):
A) Creates an empty multimap object.
B) Creates a multimap object containing one key/value pair.
C) Returns the number of times the key/value pair (15, 2.7) appears in the multimap.
D) Creates a pair object in which first is 15 (type int) and second is 2.7 (type double).
A) Creates an empty multimap object.
B) Creates a multimap object containing one key/value pair.
C) Returns the number of times the key/value pair (15, 2.7) appears in the multimap.
D) Creates a pair object in which first is 15 (type int) and second is 2.7 (type double).
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
31
If pairs is a map containing int keys and double associated values, the expression pairs[5] = 10:
A) Associates the value 10.0 to the key 5 in pairs.
B) Associates the value 5.0 to the key 10 in pairs.
C) Associates the value associated with key 10 to key 5 in pairs.
D) Associates the value associated with key 5 to key 10 in pairs.
A) Associates the value 10.0 to the key 5 in pairs.
B) Associates the value 5.0 to the key 10 in pairs.
C) Associates the value associated with key 10 to key 5 in pairs.
D) Associates the value associated with key 5 to key 10 in pairs.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
32
Assuming that bitset b1 contains the bits [0 1 1 0] and bitset b2 contains the bits [1 1 1 1], which of the following expressions returns true?
A) b1.any()
B) b1 == b2
C) b1.test(3)
D) b2.none()
A) b1.any()
B) b1 == b2
C) b1.test(3)
D) b2.none()
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
33
To pop an element off the top of a stack for processing:
A) Use member function top.
B) Use member function pop.
C) Use member function top and then member function pop.
D) Use member function pop and then member function top.
A) Use member function top.
B) Use member function pop.
C) Use member function top and then member function pop.
D) Use member function pop and then member function top.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck