Docsity

Standard Library Containers and Iterators, Exams of Advanced Education

Toggle sidebar
bg1
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.
pf3
pf4
pf5

Partial preview of the text

Download Standard Library Containers and Iterators and more Exams Advanced Education in PDF only on Docsity!

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:
  • Specify a range of elements to be removed from the vector.
  • Specify an element to be removed from the vector.
  • Be called by member function clear. *- Specify a value to be removed from the vector. - ANSWER- The expression std::multimap< int, double, std::less< int > >::value_type( 15, 2.7 ):
  • Creates an empty multimap object.
  • Returns the number of times the key/value pair ( 15, 2.7 ) appears in the multimap.
  • Creates a multimap object containing one key/value pair. *- Creates a pair object in which first is 15 (type int) and second is 2.7 (type double). - ANSWER- The list sequence container does not: Efficiently implement insert and delete operations anywhere in the list. Use a doubly linked list. Support bidirectional iterators. *Automatically sort inserted items. - ANSWER- The main difference between set and multiset is:
  • Their interface.
  • That one deals with keys only, and the other deals with key/value pairs.
  • Their efficiency. *- How they handle duplicate keys. - ANSWER- The multiset associative container does not: *- Permit random access to its keys.
  • Arrange its data in ascending order by default.
  • Need a header file to be used.
  • Use its comparator function object to determine the order of its data. - ANSWER- The order of the arguments passed to function replace_copy_if must be:
  • InputIterator, OutputIterator, PredicateFunction, ReplacementValue
  • OutputIterator, InputIterator, InputIterator, ReplacementValue, PredicateFunction *- InputIterator, InputIterator, OutputIterator, PredicateFunction, ReplacementValue
  • OutputIterator, InputIterator, ReplacementValue, PredicateFunction. - ANSWER- To pop an element off the top of a stack for processing:
  • Use member function pop. *- Use member function top and then member function pop.
  • Use member function top.
  • Use member function pop and then member function top. - ANSWER- Which of the following applications would a deque not be well suited for? *Applications that require frequent insertions and deletions at the front and at the back of a container. Applications that require frequent insertions and deletions at the back of a container.

Applications that require frequent insertions and deletions at the front of a container. Applications that require frequent insertions and deletions in the middle of a container. - ANSWER- Which of the following bitset member functions cannot be called with an empty argument list?

  • none. *- test.
  • size.
  • reset. - ANSWER- Which of the following function calls is a valid way to place elements into vector< char > chars?
  • std::generate( chars.begin(), 10, '5' );. *- std::fill( chars.begin(), chars.end(), '5' );.
  • std::generate_n( 10, chars.end(), '5' );.
  • std::fill_n( chars.begin(), chars.end(), '5' );. - ANSWER- Which of the following function calls would not return the value that is its first argument?
  • std::max( 17, 16 ).
  • std::min( 3, 23 ).
  • std::min( 'N', 'P' ). *- std::max( 'd', 'k' ). - ANSWER- Which of the following is a difference between vectors and arrays? Access to any element using the [] operator. Stored in contiguous blocks of memory. *The ability to change size dynamically. Efficient direct access to any element. - ANSWER- Which of the following is a not a member function of queue? *- enqueue.
  • empty.
  • size.
  • pop. - ANSWER- Which of the following is not a key component of the STL? Containers. *Algorithms. Pointers. Iterators. - ANSWER- Which of the following is not a mathematical algorithm included in the STL? *- copy.
  • transform.
  • min_element.