CISP 400 - Chapter 15 Standard Library
Containers and Iterators
An STL algorithm cannot:
Be used with containers that support more powerful iterators than the minimum
requirements for the algorithm.
Return an iterator.
Access STL members directly.
Take two iterators as arguments to specify a range. - ANSWER-
Attributes of a heap do not include:
- A preference to pop, rather than push, elements in the heap.
- Having a binary-tree structure.
- The children of a given node are less than or equal to the parent node's value.
- Having the largest element at the top of the heap. - ANSWER-
Class deque provides:
- The ability to add storage at either end of the deque.
*- All of the above.
- Efficient indexed access to its elements.
- Efficient insertion and deletion operations at the front and back of a deque. -
ANSWER-
Data loss could occur if the contents of a __________ were placed into any of the other
three associative container types.
*- multimap.
- map.
- multiset.
- set. - ANSWER-
Function objects have their functions called by using:
- The arrow operator (->).
- The binary scope resolution operator (::).
*- operator().
- The dot operator (.). - ANSWER-
Functions iter_swap and swap_ranges are similar in that both:
*- Take forward iterators as arguments.
- Swap a range of elements
- Take two arguments.
- Can only swap elements within the same array or container. - ANSWER-
Functions lower_bound, upper_bound and equal_range are different in their:
- First argument types.
, - Second argument types.
- Third argument types.
*- Return types. - ANSWER-
Given that v1 and v2 are vectors, the function call std::equal( v1.begin(), v1.end(),
v2.begin() ) returns:
- A bool indicating whether the first element of v1, the last element of v1 and the first
element of v2 are all equal.
*- A bool indicating whether v1 and v2 are equal.
- An iterator pointing to the first location where v1 and v2 are not equal.
- An iterator pointing to the first location where v1 and v2 are equal. - ANSWER-
If a program attempts to insert a duplicate key into a set:
- The set will contain multiple copies of that key.
- A compile error will occur.
- An exception is thrown
*- The duplicate key will be ignored. - ANSWER-
If pairs is a map containing int keys and double associated values, the expression pairs[
5 ] = 10:
- Associates the value associated with key 10 to key 5 in pairs.
- Associates the value 5.0 to the key 10 in pairs.
- Associates the value associated with key 5 to key 10 in pairs.
*- Associates the value 10.0 to the key 5 in pairs. - ANSWER-
If v1 is a vector< int > containing some number of int elements sorted in ascending
order, after these statements execute:
std::vector< int > results1;
std::vector< int > results2;
std::unique_copy( v1.begin(), v1.end(), std::back_inserter( results1 ) );
std::reverse_copy( v1.begin(), v1.end(), std::back_inserter( results2 ) );
which of the following could be true?
- results1 is empty but results2 is not.
- results1 contains more elements than results2.
- None of the above.
*- The first element in results1 matches the last element in results2. - ANSWER-
Iterators are similar to pointers because of the:
begin and end functions.
* * and ++ operators.
-> operator.
& operator. - ANSWER-
Mr. Smith has a shopping list stored in a vector. Today, Mrs. Smith decides that she will
go get the items that cost less than 10 dollars. If Mr. Smith wants to give his wife a list of
her own, he should use the function:
Containers and Iterators
An STL algorithm cannot:
Be used with containers that support more powerful iterators than the minimum
requirements for the algorithm.
Return an iterator.
Access STL members directly.
Take two iterators as arguments to specify a range. - ANSWER-
Attributes of a heap do not include:
- A preference to pop, rather than push, elements in the heap.
- Having a binary-tree structure.
- The children of a given node are less than or equal to the parent node's value.
- Having the largest element at the top of the heap. - ANSWER-
Class deque provides:
- The ability to add storage at either end of the deque.
*- All of the above.
- Efficient indexed access to its elements.
- Efficient insertion and deletion operations at the front and back of a deque. -
ANSWER-
Data loss could occur if the contents of a __________ were placed into any of the other
three associative container types.
*- multimap.
- map.
- multiset.
- set. - ANSWER-
Function objects have their functions called by using:
- The arrow operator (->).
- The binary scope resolution operator (::).
*- operator().
- The dot operator (.). - ANSWER-
Functions iter_swap and swap_ranges are similar in that both:
*- Take forward iterators as arguments.
- Swap a range of elements
- Take two arguments.
- Can only swap elements within the same array or container. - ANSWER-
Functions lower_bound, upper_bound and equal_range are different in their:
- First argument types.
, - Second argument types.
- Third argument types.
*- Return types. - ANSWER-
Given that v1 and v2 are vectors, the function call std::equal( v1.begin(), v1.end(),
v2.begin() ) returns:
- A bool indicating whether the first element of v1, the last element of v1 and the first
element of v2 are all equal.
*- A bool indicating whether v1 and v2 are equal.
- An iterator pointing to the first location where v1 and v2 are not equal.
- An iterator pointing to the first location where v1 and v2 are equal. - ANSWER-
If a program attempts to insert a duplicate key into a set:
- The set will contain multiple copies of that key.
- A compile error will occur.
- An exception is thrown
*- The duplicate key will be ignored. - ANSWER-
If pairs is a map containing int keys and double associated values, the expression pairs[
5 ] = 10:
- Associates the value associated with key 10 to key 5 in pairs.
- Associates the value 5.0 to the key 10 in pairs.
- Associates the value associated with key 5 to key 10 in pairs.
*- Associates the value 10.0 to the key 5 in pairs. - ANSWER-
If v1 is a vector< int > containing some number of int elements sorted in ascending
order, after these statements execute:
std::vector< int > results1;
std::vector< int > results2;
std::unique_copy( v1.begin(), v1.end(), std::back_inserter( results1 ) );
std::reverse_copy( v1.begin(), v1.end(), std::back_inserter( results2 ) );
which of the following could be true?
- results1 is empty but results2 is not.
- results1 contains more elements than results2.
- None of the above.
*- The first element in results1 matches the last element in results2. - ANSWER-
Iterators are similar to pointers because of the:
begin and end functions.
* * and ++ operators.
-> operator.
& operator. - ANSWER-
Mr. Smith has a shopping list stored in a vector. Today, Mrs. Smith decides that she will
go get the items that cost less than 10 dollars. If Mr. Smith wants to give his wife a list of
her own, he should use the function: