• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/43

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

43 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
Types of iterators
- input
- output
- forward
- bidirectional
- random access
Preferred method of incrementing an iterator
Prefix increment because it doesn't have to create a temporary object, thus performs better.
Key factor when choosing what type of iterator
Use the "weakest" iterator that yields acceptable performance. Helps for producing maximally reusable containers.
Iterator Hierarchy
input output
\ /
\/
forward
|
bidirectional
|
random access
Type of iterator supported by

vector
random access
Type of iterator supported by

deque
random access
Type of iterator supported by

list
bidirectional
Type of iterator supported by

set
bidirectional
Type of iterator supported by

multiset
bidirectional
Type of iterator supported by

map
bidirectional
Type of iterator supported by

multimap
bidirectional
Type of iterator supported by

stack
no iterators supported
Type of iterator supported by

queue
no iterators supported
Type of iterator supported by

priority_queue
no iterators supported
Mutating-sequence algorithms
- copy
- copy_backward
- partition
- replace_copy
- stable_partition
- random_shuffle
- replace_copy_if
- swap
- fill
- remove
- replace_if
- swap_ranges
- fill_n
- remove_copy
- reverse
- transform
- generate
- remove_copy_if
- reverse_copy
- unique
- generate_n
- remove_if
- rotate
- unique_copy
- iter_swap
- replace
- rotate_copy
Types of objects supported by STL algorithms
- STL containers
- pointer-based, C-like arrays
Nonmodifying sequence algorithms
- adjacent_find
- equal
- find_end
- mismatch
- count
- find
- find_first_of
- search
- count_if
- find_each
- find_if
- search_n
Numeric algorithms
- accumulate
- partial_sum
- inner_product
- adjacent_difference
Data structure basis for vector
array
Data structure basis for deque
array
Data structure basis for list
linked-list
Are pointer-based arrays and vectors assigned to another of the same data structure the same way?
No, vectors can be assigned to one another. Pointer-based arrays are constant pointers.
Key difference between [index ] and .at(index) for a vector?
.at() checks range before trying to access it, [ ] does not.
Functions unique to sequence containers.
- front
- back
- push_back
- pop_back
Result of calling front() or back on an empty vector
undefined
Difference between back() and end()?
back() returns a reference to the last element in the vector.
end() returns a random access iterator pointing to the end of the vector (the location after the last element).
Difference between front() and begin()?
front() returns a reference to the first element in the vector.
begin() returns a random access iterator pointing to the first element in the vector.
Functions unique to list?
- splice
- push_front
- pop_front
- remove
- remove_if
- unique
- merge
- reverse
- sort
What kind of iterators support < operator?
Only random-access iterators.
What kind of error is it to dereference an iterator positioned outside its container?
It is a runtime logic error. In particular, the iterator returned by end cannot be dereferenced or incremented.
What are the types of STL exceptions?
- out_of_range
- invalid_argument
- length_error
- bad_alloc
How are container adapters different from first-class containers?
- Adapters do not provide the actual data-structure implementation in which elements can be stored.
- Adapters do not support iterators.
What containers can be used as the underlying data structures to implement a stack adapter? Which offers the best performance?
- vector
- list
- deque

The vector offers the best performance.
What containers can be used as the underlying data structures to implement a queue adapter? Which offers the best performance?
- list
- deque (default)

The deque offers the best performance.
What operations are supported by the queue adapter?
- push
- pop
- front
- back
- empty
- size
What operations are supported by the stack adapter?
- push
- pop
- top
- empty
- size
What containers can be used as the underlying data structures for a priority_queue?
- vector (default)
- deque
What operations are supported by a priority_queue?
- push
- pop
- top
- front
- empty
- size
What data structure (not STL container) is typically used in the implementation of a priority_queue?
A heap, with the highest priority item at the top.
What does the function transform do? What is the syntax for calling it?
apply a general function to every element in the
range from v.begin() up to, but not including, v.end() in v. The general function (the
fourth argument) should take the current element as an argument, should not modify the
element and should return the transformed value. Function transform requires its first
two iterator arguments to be at least input iterators and its third argument to be at least an
output iterator. The third argument specifies where the transformed values should be
placed. Note that the third argument can equal the first. Another version of transform
accepts five arguments—the first two arguments are input iterators that specify a range of
elements from one source container, the third argument is an input iterator that specifies the first element in another source container, the fourth argument is an output iterator
that specifies where the transformed values should be placed and the last argument is a general function that takes two arguments. This version of transform takes one element from
each of the two input sources and applies the general function to that pair of elements,
then places the transformed value at the location specified by the fourth argument.
What does the function random_shuffle do? What is the syntax for calling it?
reorder randomly the elements in the range
from v.begin() up to, but not including, v.end() in v. This function takes two randomaccess iterator arguments.
What does the function accumulate do? What is the syntax for calling it?
sum the values in the range from v.begin() up to, but not including, v.end() in v. The
function’s two iterator arguments must be at least input iterators and its third argument
represents the initial value of the total. A second version of this function takes as its fourth
argument a general function that determines how elements are accumulated. The general
function must take two arguments and return a result. The first argument to this function
is the current value of the accumulation. The second argument is the value of the current
element in the sequence being accumulated.
What does the function for_each do? What is the syntax for calling it?
apply a general function to every element in the
range from v.begin() up to, but not including, v.end(). The general function takes the
current element as an argument and may modify that element (if it’s received by reference). Function for_each requires its two iterator arguments to be at least input iterators.
How do for_each and transform differ?
transform can NOT alter the elements that it receives as arguments, but for_each can.