Before using this page, you may find it useful to read the naming conventions used on this STL
reference site, and the algorithm
overview page. Or not.
The seventy algorithms available since the C++98 Standard was approved:
accumulate | adjacent_difference | adjacent_find | binary_search | copy | copy_backward | count |
count_if | equal | equal_range | fill | fill_n | find | find_end | find_first_of | find_if | for_each | generate | generate_n |
includes | inner_product | inplace_merge | iter_swap | lexicographical_compare | lower_bound | make_heap | max | max_element | merge | min | min_element | mismatch | next_permutation | nth_element | partial_sort | partial_sort_copy | partial_sum | partition | pop_heap | prev_permutation | push_heap | random_shuffle | remove | remove_copy | remove_copy_if | remove_if | replace | replace_copy | replace_copy_if | replace_if | reverse | reverse_copy | rotate |
rotate_copy | search |
search_n | set_difference | set_intersection | set_symmetric_difference | set_union | sort | sort_heap | stable_partition | stable_sort | swap | swap_ranges | transform | unique | unique_copy | upper_bound |
The sample programs illustrating the above algorithms are currently
being revised as per the C++11 Standard and the features of that standard
that are available in the version of Visual C++ found in Visual Studio
2013. You can have a look at the progress of this effort here. [The revisions are proceeding
in alphabetical order.]
The twenty new algorithms available since the C++11 Standard was
approved:
all_of | any_of | copy_if | copy_n | find_if_not | iota | is_heap | is_heap_until | is_partitioned | is_permutation | is_sorted | is_sorted_until | minmax | minmax_element | move | move_backward | none_of | partition_copy | partition_point | shuffle |
Note that is_permutation
,
minmax
, minmax_element
, move
, and
move_backward
are described but not yet illustrated with
sample programs.
- accumulate(inIterBegin, inIterEnd, val)
-
Action:
Perform val=val+containerVal for each
containerVal in the container range
[inIterBegin,inIterEnd).
Return value:
The final value of val, or the original value of
val if the input range is empty.
Complexity:
Linear in the size of the input range.
Notes:
Addition must be defined for the container component type, and
val must be of the same type as the container component
type. Thus, in effect, the algorithm computes and returns the sum
of val and all the values in the input range.
- accumulate1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to compute the sum of all integers in a
vector, and the sum of an initial value and all the integers in a
contiguous subrange of those integers.
template<class InIterator,
class T>
T accumulate(InIterator inputBegin,
InIterator inputEnd,
T val);
- accumulate(inIterBegin, inIterEnd, val, binFunc)
-
Action:
Perform val=binFunc(val,containerVal) for each
containerVal in the container range
[inIterBegin,inIterEnd).
Return value:
The final value of val, or the original value of
val if the input range is empty.
Complexity:
Linear in the size of the input range.
Notes:
binFunc must be defined for a pair of values of the
container component type, and val must be of the same type
as the container component type. Thus, in effect, the algorithm
computes and returns the "accumulated" value performed by
binFunc on all the values in the input range. This is a
more general notion of accumulation than the simple addition
performed by the default version of the algorithm given above.
- accumulate2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to compute the product of all integers in a
vector, and the product of an initial value and the values in a
contiguous subrange of those integers, using a programmer-defined
multiplication function to compute the product of two
integers.
- accumulate2b.cpp
| Windows_executable
| program_output
(text)
- Illustrates the same computations as the previous example,
but this time using a built-in STL functor to compute the product
of two integers.
template<class InIterator,
class T,
class BinaryFunc>
T accumulate(InIterator inputBegin,
InIterator inputEnd,
T val,
BinaryFunc binFunc);
- adjacent_difference(inIterBegin, inIterEnd, outIterBegin)
-
Action:
Write an output sequence in which the first value is the same as
the first value of the input sequence, and each subsequent value is
the difference between adjacent values in the input sequence.
Return value:
An iterator pointing to the end of the output range, i.e., to the
first position beyond the last value of the output sequence.
Complexity:
Linear in the size of the input range.
Notes:
Values in the output range are overwritten, starting with the
value at outIterBegin. The value at position n in the
output range is obtained by subtracting the value at position n-1
is subtracted from the value at position n in the input range. The
range [inIterBegin,inIterEnd) determines the portion of
the input container to which the algorithm will be applied and
outIterBegin points to the first value of the output range
in the output container.
- adjacent_difference1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to compute adjacent differences for the
integer values in one vector and write those values to a second
vector. Also shows the value pointed to by the iterator returned
by the algorithm.
template<class InIterator,
class OutIterator>
OutIterator adjacent_difference(InIterator inIterBegin,
InIterator inIterEnd,
OutIterator outIterBegin);
- adjacent_difference(inIterBegin, inIterEnd, outIterBegin,
binFunc)
-
Action:
Perform in a manner analogous to the version of the algorithm given
above, except that this time binFunc is applied to
adjacent elements, rather than simply computing their difference.
Return value:
An iterator pointing to the end of the output range, i.e., to the
first position beyond the last value of the output sequence.
Complexity:
Linear in the size of the input range.
Notes:
Values in the output range are overwritten, starting with the
value at outIterBegin. The value at position n in the
output range is obtained by supplying the value at position n in
the input range as the first argument of binFunc and the
value at position n-1 in the input range as the second argument of
binFunc, and then evaluating binFunc. The range
[inIterBegin,inIterEnd) determines the portion of the
input container to which the algorithm will be applied and
outIterBegin points to the first value of the output range
in the output container.
- adjacent_difference2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to apply the simple function
f(a,b)=2*a+b to successive pairs of integer values in
one vector, and write the resulting values to a second vector.
Also shows the value pointed to by the iterator returned by the
algorithm.
template<class InIterator,
class OutIterator,
class BinaryFunc>
OutIterator adjacent_difference(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
BinaryFunc binFunc);
- adjacent_find(forIterBegin,forIterEnd)
-
Action:
Search for adjacent equal values in the range
[forIterBegin,forIterEnd).
Return value:
An iterator pointing to the first element of the first equal
adjacent pair, or to forIterEnd if no such matching pair
is found.
Complexity:
Linear in the size of the input range.
Notes: none
- adjacent_find1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the first pair of equal values within
a range of values.
template<class ForIterator>
ForIterator adjacent_find(ForIterator searchRangeBegin,
ForIterator searchRangeEnd);
- adjacent_find(forIterBegin, forIterEnd, binPred)
-
Action:
Perform in a manner analogous to the version of the algorithm
given above, except that in this case binPred is applied
to adjacent values to determine if they match.
Return value:
An iterator pointing to the first value of the first matching pair
of values, or to forIterEnd if no such matching pair is
found.
Complexity:
Linear in the size of the input range.
Notes: none
- adjacent_find2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find, within a range of values, the first
adjacent pair of values that are both divisible by 5.
template<class ForIterator,
class BinaryPred>
ForIterator adjacent_find(ForIterator searchRangeBegin,
ForIterator searchRangeEnd,
BinaryPred matchTestPred);
- binary_search(forIterBegin, forIterEnd, targetVal)
-
Action:
Perform a binary search for a value equal to targetVal
within the range [forIterBegin,forIterEnd).
Return value:
true if the value is found, and otherwise false.
Complexity:
Logarithmic in the size of the input range for random-access iterators,
otherwise linear.
Notes:
In this version of the algorithm the values in the search range
are assumed to be sorted in ascending order.
- binary_search1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to determine whether a specific value is one
of the values in a given range of values that have been sorted
into ascending order.
template<class ForIterator,
class T>
bool binary_search(ForIterator searchRangeBegin,
ForIterator searchRangeEnd,
const T& targetVal);
- binary_search(forIterBegin, forIterEnd, targetVal, binPred)
-
Action:
Perform in a manner analogous to the version of the algorithm
given above, except that in this case the criterion for ordering
the values in the search range is the one give by
programmer-supplied comparison function binPred.
Return value:
true if the value is found, and otherwise false.
Complexity:
Logarithmic in the size of the input range for random-access iterators,
otherwise linear.
Notes: none
- binary_search2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to determine whether an integer having the
same digit sum as a given integer is present among the integers
within a given range of integers. The given range of integers is
assumed to be ordered in the sense that a first integer precedes
a second integer if the sum of the digits in the first integer is
less than the sum of the digits in the second integer.
template<class ForIterator,
class T,
class BinaryPred>
bool binary_search(ForIterator searchRangeBegin,
ForIterator searchRangeEnd,
const T& targetVal,
BinaryPred comparisonPred);
- copy(inIterBegin, inIterEnd, outIterBegin)
-
Action:
Copy, in forward order, the sequence of values from the input
range [inIterBegin,inIterEnd) in a source container to a
destination container output range whose first element is pointed
to by outIterBegin.
Return value:
An iterator pointing to the end (one-past-the-last) of the copied
range in the destination container.
Complexity:
Linear in the size of the input range.
Notes:
The output range in the destination container must be large enough
to receive the copied values. Values in the destination container
are overwritten by default, starting with the value at position
outIterBegin. The range to be copied must not overlap with
outIterBegin in any case where the source container and
the destination container are the same.
- copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to copy integers (in the forward direction)
from one vector to another, and also illustrates what value is
pointed to by the iterator returned by the algorithm.
- copy1b.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to copy integers (in the forward direction)
from a vector to an output stream using an output stream
iterator.
template<class InIterator,
class OutIterator>
OutIterator copy(InIterator sourceRangeBegin,
InIterator sourceRangeEnd,
OutIterator destinationRangeBegin);
- copy_backward(biIter1Begin, biIter1End, biIter2End)
-
Action:
Copy, in reverse order, the sequence of values from an input range
[biIter1Begin,biIter1End) in a source container to an
output range in a destination container. The end of the output
range is pointed to by biIter2End.
Return value:
An iterator pointing to the last value copied.
Complexity:
Linear in the size of the input range.
Notes:
The output range in the destination container must be large enough
to receive the copied values. Values in the destination container
are overwritten by default. The iterator biIter2End marks
the end of the range of copied values in the destination container.
Conceptually, this implies that the first value copied is the value
at position biIter1End-1, and it is copied to position
biIter2End-1. The range to be copied must not overlap with
biIter2End, in the case where the source container and the
destination container are the same.
- copy_backward1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to copy integers (in the backward direction)
from one vector to another, and also illustrates what value is
pointed to by the iterator returned by the algorithm.
template<class BiIterator1,
class BiIterator2>
BiIterator2 copy_backward(BiIterator1 sourceRangeBegin,
BiIterator1 sourceRangeEnd,
BiIterator2 destinationRangeEnd);
- count(inIterBegin, inIterEnd, val)
-
Action:
Count the number of values in an input range
[inIterBegin,inIterEnd) that equal val.
Return value:
The number of such values.
Complexity:
Linear in the size of the input range.
Notes: none
- count1a.cpp | Windows_executable |
program_output
(text)
- Illustrates how to count the integers in a vector that equal
a particular integer value.
template<class InIterator,
class T>
difference_type count(InIterator inputBegin,
InIterator inputEnd,
const T& targetValue);
- count_if(inIterBegin, inIterEnd, unPred)
-
Action:
Count the number of values in an input range
[inIterBegin,inIterEnd) for which the unary predicate
unPred returns true.
Return value:
The number of such values.
Complexity:
Linear in the size of the input range.
Notes: none
- count_if1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to count the integer values that are
divisible by 3 in a vector of integers.
template<class InIterator,
class UnaryPred>
difference_type count_if(InIterator inputBegin,
InIterator inputEnd,
UnaryPred matchTestPred);
- equal(inIter1Begin, inIter1End, inIter2Begin)
-
Action:
Compare the sequence of values from the
range [inIter1Begin,inIter1End) with the sequence in the
range whose first value is pointed to by inIter2Begin.
Return value:
true if both ranges
contain equal values in corresponding positions, and otherwise
false.
Complexity:
Linear in the size of the input range.
Notes:
The range starting at
inIter2Begin may contain more, but not fewer, values than
the range given by [inIter1Begin,inIter1End).
- equal1a.cpp | Windows_executable |
program_output
(text)
- Illustrates how to test whether the integers in a range of
integers in one vector are the same as the integers in another
range in a different vector.
template<class InIterator1,
class InIterator2>
bool equal(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin);
- equal(inIter1Begin, inIter1End, inIter2Begin, binPred)
-
Action:
Perform in a manner analogous to the
previous version of the algorithm given above, except that in this
case binPred is used to determine when two values match
(i.e., are "equal").
Return value:
true if both ranges
contain matching values in corresponding positions, and otherwise
false.
Complexity:
Linear in the size of the input range.
Notes:
The range starting at
inIter2Begin may contain more, but not fewer, values than
the range given by [inIter1Begin,inIter1End).
- equal2a.cpp | Windows_executable |
program_output
(text)
- Illustrates how to test whether the integers in a range of
integers in one vector match the integers in another range in a
different vector, in the sense of values in corresponding
positions having the same digit sum.
template<class InIterator1,
class InIterator2,
class BinaryPred>
bool equal(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
BinaryPred matchTestPred);
- pair<ForIterator, ForIterator> equal_range(forIterBegin,
forIterEnd, targetVal)
-
Action:
Find the lower and upper bounds of
targetVal within the range
[forIterBegin,forIterEnd).
Return value:
A pair of iterators in
which the first iterator points to the location of the lower bound
of targetVal within the given range and the second
iterator points to the upper bound of targetVal within
that range.
Complexity:
Logarithmic in the size of the input range for random access iterators,
otherwise linear.
Notes:
The values in
[forIterBegin,forIterEnd) are assumed to be sorted in
ascending order. A lower and/or upper bound iterator may in fact be
the end (one-past-the-last) of the range.
- equal_range1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the lower and upper bounds of integer
values in a vector of integers that are sorted in ascending
order.
template<class ForIterator,
class T>
pair<ForIterator, ForIterator> equal_range(ForIterator inputBegin,
ForIterator inputEnd,
const T& targetVal);
- pair<ForIterator, ForIterator> equal_range(forIterBegin,
forIterEnd, targetVal, binPred)
-
Action:
Perform in a manner analogous to the
previous version of the algorithm given above, except that in this
case binPred determines the ordering of the values in
[forIterBegin,forIterEnd).
Return value:
A pair of iterators in
which the first iterator points to the location of the lower bound
of targetVal within the given range and the second
iterator points to the upper bound of targetVal within
that range.
Complexity:
Logarithmic in the size of the input range for random access iterators,
otherwise linear.
Notes:
The values in
[forIterBegin,forIterEnd) are assumed to be ordered in the
sense that a precedes b if and only if
binPred(a,b) is true. A lower and/or upper bound
iterator may in fact be the end (one-past-the-last) of the range.
- equal_range2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find lower and upper bounds of integers in
a vector of integers that have been ordered in the sense that one
integer precedes another if the first has a smaller digit sum
than the second.
template<class ForIterator,
class T,
class BinaryPred>
pair<ForIterator, ForIterator> equal_range(ForIterator inputBegin,
ForIterator inputEnd,
const T& targetVal,
BinaryPred comparisonPred);
- fill(forIterBegin, forIterEnd, val)
-
Action:
Set every item in a range [forIterBegin,forIterEnd) to
val.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
The type of val must be the same as the component type of
values in the range [forIterBegin,forIterEnd).
- fill1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to set all values in a range of values within
a vector of integers to a given value.
template<class ForIterator,
class T>
void fill(ForIterator outputBegin,
ForIterator outputEnd,
const T& val);
- fill_n(outIterBegin, num, val)
-
Action:
Set num items to val in a range that begins at
outIterBegin.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
The type of val must be the same as the component type of
values in the range beginning at outIterBegin.
- fill_n1a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to set a particular number of integers in a
vector of integers, starting at a specific point in the vector,
to a given value.
template<class OutIterator,
class size_type,
class T>
void fill_n(OutIterator outputBegin,
size_type num,
const T& val);
- find(inIterBegin, inIterEnd, targetVal)
-
Action:
Search for a value equal to targetVal in a range
[inIterBegin,inIterEnd).
Return value:
An iterator pointing at the first occurrence of such a value, or
at inIterEnd if no such value is found.
Complexity:
Linear in the size of the input range.
Notes:
The type of targetVal must be the same as the component
type of values in the range [inIterBegin,inIterEnd) This
is a sequential search, so no assumptions are made about any
ordering of the values in the input range.
- find1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find a given integer value within a vector
of integers.
template<class InIterator,
class T>
InIterator find(InIterator searchRangeBegin,
InIterator searchRangeEnd,
const T& targetVal);
- find_end(forIter1Begin, forIter1End, forIter2Begin,
forIter2End)
-
Action:
Search for the last occurrence of the range of values given by
[forIter2Begin,forIter2End) within the range of values
given by [forIter1Begin,forIter1End).
Return value:
An iterator pointing to the first value of the matching range
within [forIter1Begin,forIter1End) if such a matching
range is found, and to forIter1End if there is no matching
range.
Complexity:
Linear in the size of the input range times the size of the search range.
Notes:
For a "matching range" to exist, corresponding values in the
ranges must be equal.
- find_end1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the last occurrence of one range of
integer values in a vector within another range of integer values
in a vector.
template<class ForIterator1,
class ForIterator2>
ForIterator1 find_end(ForIterator1 searchRange1Begin,
ForIterator1 searchRange1End,
ForIterator2 searchRange2Begin,
ForIterator2 searchRange2End);
- find_end(forIter1Begin, forIter1End, forIter2Begin, forIter2End,
binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the test applied to
corresponding elements to determine if the ranges match is
performed by binPred.
Return value:
An iterator pointing to the first value of the matching range
within [forIter1Begin,forIter1End) if such a matching
range is found, and to forIter1End if there is no matching
range.
Complexity:
Linear in the size of the input range times the size of the search range.
Notes:
For a "matching range" to exist, binPred applied to
corresponding values from the two ranges must return true.
- find_end2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the last occurrence of one range of
integer values in a vector within another range of integer values
in a vector, and for which corresponding values in the two ranges
match if and only if they have the same digit sum.
template<class ForIterator1,
class ForIterator2,
class BinaryPred>
ForIterator1 find_end(ForIterator1 searchRange1Begin,
ForIterator1 searchRange1End,
ForIterator2 searchRange2Begin,
ForIterator2 searchRange2End,
BinaryPred matchTestPred);
- find_first_of(forIter1Begin, forIter1End, forIter2Begin,
forIter2End)
-
Action:
Search for the first instance of any of the values in
[forIter2Begin,forIter2End) also occurring in the range
[forIter1Begin,forIter1End).
Return value:
An iterator pointing to this first such instance if one is found,
and to forIter1End if there is no matching value.
Complexity:
Linear in the size of the input range.
Notes:
In this search, values match if they are equal.
- find_first_of1a.cpp
| Windows_executable|
program_output
(text)
- Illustrates how to find the first occurrence of any one of a
range of integer values in a vector within another range of
integer values, also in a vector.
template<class ForIterator1,
class ForIterator2>
ForIterator1 find_first_of(ForIterator1 searchRange1Begin,
ForIterator1 searchRange1End,
ForIterator2 searchRange2Begin,
ForIterator2 searchRange2End);
- find_first_of(forIter1Begin, forIter1End, forIter2Begin,
forIter2End, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the test applied to
corresponding values to determine if they match is performed by
binPred.
Return value:
An iterator pointing to this first such instance if one is found,
and to forIter1End if there is no matching value.
Complexity:
Linear in the size of the input range.
Notes:
In this search, values valFromFirstRange and
valFromSecondRange match if
binPred(valFromFirstRange,valFromSecondRange) returns
true.
- find_first_of2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the first occurrence of any one of a
range of integer values in a vector within another range of
integer values, also in a vector, and where corresponding values
match if and only if they have the same digit sum.
template<class ForIterator1,
class ForIterator2,
class BinaryPred>
ForIterator1 find_first_of(ForIterator1 searchRange1Begin,
ForIterator1 searchRange1End,
ForIterator2 searchRange2Begin,
ForIterator2 searchRange2End,
BinaryPred matchTestPred);
- find_if(inIterBegin, inIterEnd, unPred)
-
Action:
Search the range [inIterBegin, inIterEnd) for a value
that satisfies the unary predicate unPred.
Return value:
An iterator pointing to the first value from the given range that
satisfies unPred, or inIterEnd if no such value
is found.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- find_if1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to find an integer divisible by 3 in a vector
of integers.
template<class InIterator,
class UnaryPred>
InIterator find_if(InIterator searchRangeBegin,
InIterator searchRangeEnd,
UnaryPred matchTestPred);
- for_each(inIterBegin, inIterEnd, unProc)
-
Action:
Apply the unary procedure unProc to every item in a range
[inIterBegin,inIterEnd).
Return value: unProc
Complexity:
Linear in the size of the input range.
Notes:
The unary procedure unProc must take a single parameter
that has the same type as the values in the range
[inIterBegin,inIterEnd).
- for_each1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates finding cube of, and how to display, values in a
vector of doubles using the for_each() algorithm.
template<class InIterator,
class UnaryProc>
UnaryProc for_each(InIterator inputBegin,
InIterator inputEnd,
UnaryProc unProc);
- generate(forIterBegin, forIterEnd, genFunc)
-
Action:
Fill the range [forIterBegin, forIterEnd) with values
generated by the generator function genFunc.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
genFunc is a function that takes no parameters and
returns a value of the same type as the component type of the
values in the range [forIterBegin, forIterEnd).
- generate1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to generate a range of random integer values
in a vector by using the rand function from
<cstdlib>.
template<class ForIterator,
class GeneratorFunc>
void generate(ForIterator outputBegin,
ForIterator outputEnd,
GeneratorFunc genFunc);
- generate_n(outIterBegin, num, genFunc)
-
Action:
Fill the range starting at outIterBegin with num
values generated by the generator function genFunc.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
genFunc is a function that takes no parameters and
returns a value of the same type as the component type of the
values in the output range starting at outIterBegin.
- generate_n1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to generate num random integer
values for a vector range of values starting at
outIterBegin by using the rand function from
<cstdlib>. The output range starting at
outIterBegin must be large enough to receive the
generated values.
template<class OutIterator,
class size_type,
class GeneratorFunc>
void generate_n(OutIterator outputBegin,
size_type num,
GeneratorFunc genFunc);
- includes(inIter1Begin, inIter1End, inIter2Begin, inIter2End)
-
Action:
Search for each value from the range
[inIter2Begin,inIter2End) in the range
[inIter1Begin,inIter1End).
Return value:
true if all the values from the second range are found in
the first range, and otherwise false.
Complexity:
Linear in the number of elements to search for plus the number of
elements to search through.
Notes:
Both ranges are assumed to be sorted in ascending order. The
values from the second range do not have to be contiguous in the
first range.
- includes1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test whether the values in a second
(sorted ascending) range of integer values in a vector of
integers are all present in a first (sorted ascending) range of
integer values, also in a vector of integers.
template<class InIterator1,
class InIterator2>
bool includes(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End);
- includes(inIter1Begin, inIter1End, inIter2Begin, inIter2End,
binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred determines the ordering of values in the
given range.
Return value:
true if each value from the second range matches a value
found in the first range, and otherwise false.
Complexity:
Linear in the number of elements to search for plus the number of
elements to search through.
Notes:
Both ranges are assumed to be ordered in the sense that value
a precedes value b if and only if
binPred(a,b) returns true. The values from the
second range do not have to be contiguous in the first range.
- includes2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test whether the values in a second range
of (ordered) integer values in a vector of integers are all
present in a first (ordered) range of integer values, also in a
vector of integers. In this case the integers are ordered in the
sense that a first integer precedes a second if and only if its
digit sum is less than the digit sum of the second integer.
template<class InIterator1,
class InIterator2,
class BinaryPred>
bool includes(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End,
BinaryPred comparisonPred);
- inner_product(inIter1Begin, inIter1End, inIter2Begin, val)
-
Action:
Calculate the sum of the products of two ranges of values,
[inIter1Begin,inIter1End) and the one beginning at
inIter2Begin, by taking the corresponding values in each
range, multiplying those values, and then adding the result to a
total initialized by val. In other word, the algorithm
performs val=val+(container1Val*container2Val) for each
corresponding pair of values in the two container ranges.
Return value:
The final value of val or, if the first range is empty,
the initial value of val.
Complexity:
Linear in the size of the input range.
Notes:
The range starting with inIter2Begin must contain at
least the number of values in the range
[inIter1Begin,inIter1End).
- inner_product1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to compute the "standard" inner product
(i.e., the sum of the products) of two ranges of integer values
from two vectors of integers.
template<class InIterator1,
class InIterator2,
class T>
T inner_product(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
T initializerVal);
- inner_product(inIter1Begin, inIter1End, inIter2Begin, val,
binFunc1, binFunc2)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the programmer can
compute a non-standard inner product by supplying two function
operators to replace the addition and multiplication operations
that are used in the first (standard) version. In other words, this
version of the algorithm performs
val=binFunc1(val,binFunc2(container1Val,container2Val))
for each corresponding pair of values in the two container ranges.
Return value:
The final value of val or, if the first range is empty,
the initial value of val.
Complexity:
Linear in the size of the input range.
Notes:
The range starting with inIter2Begin must contain at
least the number of values in the range
[inIter1Begin,inIter1End).
- inner_product2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to compute the inner product of two ranges of
integer values from two vectors of integers. This time
multiplication is replaced by addition and addition by
multiplication, so that instead of the "usual" inner product,
which is the sum of products, we have the product of sums.
template<class InIterator1,
class InIterator2,
class T,
class BinaryFunc1,
class BinaryFunc2>
T inner_product(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
T initializerVal,
BinaryFunc1 binFunc1,
BinaryFunc2 binFunc2);
- inplace_merge(biIterBegin, biIterMid, biIterEnd)
-
Action:
Combine the two (sorted) ranges of values in [biIterBegin,
biIterMid) and [biIterMid, biIterEnd) into a single
(sorted) range of values in [biIterBegin, biIterEnd).
Return value: void
Complexity:
Linear in the size of the input range if enough memory is available;
otherwise n*log n where n is the size of the input range.
Notes:
The two input ranges must be sorted in ascending order and the
combined output range will also be sorted in ascending order.
- inplace_merge1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to merge two sorted ranges of in the same
container into a single sorted range of values within that same
container.
template<class BiIterator>
void inplace_merge(BiIterator inputOutputBegin,
BiIterator inputOutputMid,
BiIterator inputOutputEnd);
- inplace_merge(biIterBegin, biIterMid, biIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version, except that
in this case the order of values is determined by the supplied
comparison function.
Return value: void
Complexity:
Linear in the size of the input range if enough memory is available;
otherwise n*log n where n is the size of the input range.
Notes:
The two input ranges must be ordered by the comparison predicate
binPred in the sense that the value a precedes
the value b if and only if binPred(a,b) returns
true.
- inplace_merge2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to merge two ordered ranges in the same
container into a single ordered range of values within that same
container. In this case the order of values is determined by one
value preceding another if the first has a smaller digit sum than
the second.
template<class BiIterator,
class BinaryPred>
void inplace_merge(BiIterator inputOutputBegin,
BiIterator inputOutputMid,
BiIterator inputOutputEnd,
BinaryPred comparisonPred);
- iter_swap(forIter1, forIter2)
-
Action:
Swap the values pointed to by the two iterators forIter1
and forIter2.
Return value: void
Complexity:
Constant time.
Notes:
The values to be swapped may be in the same container or different
containers.
- iter_swap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to swap integer values that are pointed to by
two different iterators that may point into the same vector of
integers, or into two different vectors of integers.
template<class ForIterator1,
class ForIterator2>
void iter_swap(ForIterator1 forIter1,
ForIterator2 forIter2);
- lexicographical_compare(inIter1Begin, inIter1End, inIter2Begin,
inIter2End)
-
Action:
Determine whether the range [inIter1Begin,inIter1End)
precedes the range [inIter2Begin,inIter2End) in
"dictionary order".
Return value:
true if the first range would precede the second in
"dictionary order", and otherwise false.
Complexity:
Linear in the size of the smaller container.
Notes:
Both ranges must be sorted in ascending order.
- lexicographical_compare1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test whether a range of integers in one
vector precedes, in the lexicographical (dictionary) sense,
another range of integers, in the same vector, or in another
vector.
template<class InIterator1,
class InIterator2>
bool lexicographical_compare(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End);
- lexicographical_compare(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the order of values
is determined by the supplied comparison predicate.
Return value:
true if the first range would precede the second in
"dictionary order", and otherwise false.
Complexity:
Linear in the size of the smaller container.
Notes:
Both ranges must be ordered as determined by the supplied
comparison predicate.
- lexicographical_compare2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test whether a range of integers in one
vector precedes, in the lexicographical (dictionary) sense,
another range of integers, in the same vector, or in another
vector. In this case, the integer values are ordered in the sense
that one integer precedes another if and only if the digit sum of
the first is less than the digit sum of the second.
template<class InIterator1,
class InIterator2,
class BinaryPred>
bool lexicographical_compare(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End,
BinaryPred comparisonPred);
- lower_bound(forIterBegin, forIterEnd, targetVal)
-
Action:
Find the location of the lower bound of targetVal within
the (sorted) range [forIterBegin,forIterEnd).
Return value:
An iterator pointing to this location, which will be the first
location in the given range where the value is not less than
targetVal, or the end of the range if there is no such
value. Equivalently, it's the first location where
targetVal could be inserted without destroying the sort
order.
Complexity:
Logarithmic in the size of the input range for random access iterators,
otherwise linear.
Notes:
The values in the range [forIterBegin,forIterEnd) must be
sorted in ascending order.
- lower_bound1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the lower bound location of a given
target value in a vector of integers sorted in ascending
order.
template<class ForIterator,
class T>
ForIterator lower_bound(ForIterator inputBegin,
ForIterator inputEnd,
const T& targetVal);
- lower_bound(forIterBegin, forIterEnd, targetVal, binPred)
-
Action:
Perform in a manner analogous to the previous version, except that
in this case the order of values is determined by the supplied
comparison predicate binPred.
Return value:
An iterator pointing to the location of the lower bound of
targetVal, which will be the first location in the given
range where targetVal could be inserted without destroying
the given value order determined by binPred, or the end of
the range if there is no such value.
Complexity:
Logarithmic in the size of the input range for random access iterators,
otherwise linear.
Notes:
The range of values [forIterBegin,forIterEnd) must be
ordered as determined by the supplied comparison predicate.
- lower_bound2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the lower bound location of a given
target value in a vector of integers ordered in the sense that one
integer precedes another if the digit sum in the first is less than
the digit sum in the second.
template<class ForIterator,
class T,
class BinaryPred>
ForIterator lower_bound(ForIterator inputBegin,
ForIterator inputEnd,
const T& targetVal,
BinaryPred comparisonPred);
- make_heap(randIterBegin, randIterEnd)
-
Action:
Make a range of values [randIterBegin,randIterEnd) into a
(maximum) heap.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
To understand and make use of this algorithm you should already
know what a heap is and how it is represented in contiguous
storage, or you should look up this information elsewhere.
- make_heap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to convert an arbitrary vector of integers
into a (maximum) heap.
template<class RandIterator>
void make_heap(RandIterator inputBegin,
RandIterator inputEnd);
- make_heap(randIterBegin, randIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the programmer can
supply a comparison predicate that determines when one element
comes before another.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
To understand and make use of this algorithm you should already
know what a heap is and how it is represented in contiguous
storage, or you should look up this information elsewhere.
- make_heap2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to convert an arbitrary vector of integers
into a heap. In this case, the built-in predicate functor
greater<int>() is used to order the values.
template<class RandIterator,
class BinaryPred>
void make_heap(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- max(val1, val2)
-
Action:
Find the greater of two values.
Return value:
The greater of val1 and val2, or val1
if the two values are equal.
Complexity:
Constant time.
Notes:
In this version of the algorithm, values are compared using the
usual < operator.
- max1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to find the maximum of two literal integer
values, two integer values stored in simple integer variables,
and two integer values stored as array elements.
template<class T>
const T& max(const T& val1,
const T& val2);
- max(val1, val2, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
The greater of val1 and val2, or val1
if the two values are equal.
Complexity:
Constant time.
Notes:
In this version of the algorithm, values are compared using the
predicate function binPred, in the sense that
val1 "precedes" or "is less than" val2 if and
only if binPred(val1,val2) returns true.
- max2a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to find the maximum of two literal integer
values, two integer values stored in simple integer variables,
and two integer values stored as array elements, when the
criterion for one integer to be greater than another is that it
have a greater digit sum.
template<class T,
class BinaryPred>
const T& max(const T& val1,
const T& val2,
BinaryPred comparisonPred);
- max_element(forIterBegin, forIterEnd)
-
Action:
Find the largest value in the range
[forIterBegin,forIterEnd).
Return value:
An iterator pointing to the largest value in the given range.
Complexity:
Linear in the size of the input range.
Notes:
In this version of the algorithm, values are compared using the
usual < operator.
- max_element1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the largest value in a vector of
integers.
template<class ForIterator>
ForIterator max_element(ForIterator inputBegin,
ForIterator inputEnd);
- max_element(forIterBegin, forIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
An iterator pointing to the largest value in the given range,
according to the criterion determined by binPred.
Complexity:
Linear in the size of the input range.
Notes:
In this version of the algorithm, values are compared using the
predicate function binPred, in the sense that a value
a "precedes" or "is less than" a value b if and
only if binPred(a,b2) returns true.
- max_element2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the largest value in a vector of
integers, when one integer is greater than another if and only if
it has a greater digit sum.
template<class ForIterator,
class BinaryPred>
ForIterator max_element(ForIterator inputBegin,
ForIterator inputEnd,
BinaryPred comparisonPred);
- merge(inIter1Begin, inIter1End, inIter2Begin, inIter2End,
outIterBegin)
-
Action:
Combine two sorted ranges [inIter1Begin,inIter1End) and
[inIter2Begin,inIter2End) into a single sorted range
pointed to by outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the range sizes.
Notes:
Both input ranges must be sorted in ascending order, and the output
range will be as well. The algorithm is stable, in that both the
relative order of values within each input range is preserved, and
for equivalent values in both ranges the value from the first range
precedes the value from the second range. The output range must be
large enough to receive the merged range of values.
- merge1a.cpp | Windows_executable |
program_output
(text)
- Illustrates how to merge two sorted ranges of integers in a
vector of integers into a single sorted range of integers, also
in a vector of integers.
template<class InIterator1,
class InIterator2,
class OutIterator>
OutIterator merge(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End,
OutIterator outputBegin);
- merge(inIter1Begin, inIter1End, inIter2Begin, inIter2End,
outIterBegin, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the range sizes.
Notes:
Both input ranges must be ordered by binPred in the sense
that a value a "precedes" or "is less than" a value
b if and only if binPred(a,b2) returns
true, and the output range will also be ordered in this
way. The algorithm is stable, in that both the relative order of
values within each input range is preserved, and for equivalent
values in both ranges the value from the first range precedes the
value from the second range. The output range must be large enough
to receive the merged range of values.
- merge2a.cpp | Windows_executable |
program_output
(text)
- Illustrates how to merge two sorted ranges of integers in a
vector of integers into a single sorted range of integers, also
in a vector of integers, when one integer precedes another if and
only if it has a smaller digit sum.
template<class InIterator1,
class InIterator2,
class OutIterator,
class BinaryPred>
OutIterator merge(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End,
OutIterator outputBegin,
BinaryPred comparisonPred);
- min(val1, val2)
-
Action:
Find the smaller of two values.
Return value:
The smaller of val1 and val2, or val1
if the two values are equal.
Complexity:
Constant time.
Notes:
In this version of the algorithm, values are compared using the
usual < operator.
- min1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to find the minimum of two literal integer
values, two integer values stored in simple integer variables,
and two integer values stored as array elements.
template<class T>
const T& min(const T& i,
const T& j);
- min(val1, val2, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
The smaller of val1 and val2, or val1
if the two values are equal.
Complexity:
Constant time.
Notes:
In this version of the algorithm, values are compared using the
predicate function binPred, in the sense that
val1 "precedes" or "is less than" val2 if and
only if binPred(val1,val2) returns true.
- min2a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to find the minimum of two literal integer
values, two integer values stored in simple integer variables,
and two integer values stored as array elements, when the
criterion for one integer to be less than another is that it
have a smaller digit sum.
template<class T,
class BinaryPred>
const T& min(const T& i,
const T& j,
BinaryPred comparisonPred);
- min_element(forIterBegin, forIterEnd)
-
Action:
Find the smallest value in the range
[forIterBegin,forIterEnd).
Return value:
An iterator pointing to the smallest value in the given range.
Complexity:
Linear in the size of the input range.
Notes:
In this version of the algorithm, values are compared using the
usual < operator.
- min_element1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the smallest value in a vector of
integers.
template<class ForIterator>
ForIterator min_element(ForIterator inputBegin,
ForIterator inputEnd);
- min_element(forIterBegin, forIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
An iterator pointing to the smallest value in the given range,
according to the criterion determined by binPred.
Complexity:
Linear in the size of the input range.
Notes:
In this version of the algorithm, values are compared using the
predicate function binPred, in the sense that a value
a "precedes" or "is less than" a value b if and
only if binPred(a,b2) returns true.
- min_element2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the smallest value in a vector of
integers, when one integer is greater than another if and only if
it has a greater digit sum.
template<class ForIterator,
class BinaryPred>
ForIterator min_element(ForIterator inputBegin,
ForIterator inputEnd,
BinaryPred comparisonPred);
- pair<InIterator1, InIterator2> mismatch(inIter1Begin,
inIter1End, inIter2Begin)
-
Action:
Search the range [inIter1Begin,inInter1End) and the range
beginning at inIter2Begin for the first pair of mismatched
(unequal) values.
Return value:
A pair of iterators pointing to the mismatched values in
both ranges. If no mismatched values are found it returns a pair of
iterators in which the first iterator is pointing to the end
(one-past-the-last) of the first range, and the second iterator is
pointing at the corresponding value in the second range. Note that
in this latter case this second iterator may also point to
the end of the second range, but doesn't have to, and won't if the
second range contains more values than the first.
Complexity:
Linear in the size of the input range.
Notes:
The second range must contain at least as many values as the
first.
- mismatch1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find mismatched values in two ranges of
integers from two vectors of integers when simple equality is
used to determine if two integer values match.
template<class InIterator1,
class InIterator2>
pair<InIterator1, InIterator2> mismatch(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2);
- pair<InIterator1, InIterator2> mismatch(inIter1Begin,
inIter1End, inIter2Begin, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case binPred is
applied to corresponding values from the two ranges to determine if
they match.
Return value:
A pair of iterators pointing to the mismatched values in
both ranges. If no mismatched values are found it returns a pair of
iterators in which the first iterator is pointing to the end
(one-past-the-last) of the first range, and the second iterator is
pointing at the corresponding value in the second range. Note that
in this latter case this second iterator may also point to
the end of the second range, but doesn't have to, and won't if the
second range contains more values than the first.
Complexity:
Linear in the size of the input range.
Notes:
The second range must contain at least as many values as the
first.
- mismatch2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find mismatched values in two ranges of
integers from two vectors of integers when the sum of digits is
used to determine if two integer values match.
template<class InIterator1,
class InIterator2,
class BinaryPred>
pair<InIterator1, InIterator2> mismatch(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
BinaryPred matchTestPred);
- next_permutation(biIterBegin, biIterEnd)
-
Action:
Transform the sequence of values in the range
[biIterBegin,biIterEnd) into the next "largest"
lexicographic permutation of those values, or, if that next
permutation does not exist, transform the sequence of values into
the lexicographically smallest permutation of those values (i.e.,
sort the sequence to its first permutation).
Return value:
true if in fact there was a next permutation, and
otherwise false.
Complexity:
Linear in the size of the input range.
Notes:
The permutations are generated assuming a range of values sorted
in ascending order.
- next_permutation1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to generate all permutations of a vector of
integers, in order, and also to demonstrate what happens to the
return value of the algorithm when the "end" of a permutation
sequence is reached and we then "roll over" to begin a new
sequence.
template<class BiIterator>
bool next_permutation(BiIterator inputBegin,
BiIterator inputEnd);
- next_permutation(biIterBegin, biIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
true if in fact there was a next permutation, and
otherwise false.
Complexity:
Linear in the size of the input range.
Notes:
The permutations are generated assuming a range of values with an
order determined by binPred.
- next_permutation2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to generate all permutations of a vector of
integers, in order, and also to demonstrate what happens to the
return value of the algorithm when the "end" of a permutation
sequence is reached and we then "roll over" to begin a new
sequence. In this case the order of the integers in a permutation
is determined by one integer preceding another if and only if it
has a smaller digit sum.
template<class BiIterator,
class BinaryPred>
bool next_permutation(BiIterator inputBegin,
BiIterator inputEnd,
BinaryPred comparisonPred);
- nth_element(randIterBegin, randIterNthVal, randIterEnd)
-
Action:
Partition the range [randIterBegin,randIterEnd) in such a
way that the value pointed to by the iterator
randIterNthVal is the same as the element that would be in
that position if the entire range had been sorted. Viewing this
value as the "Nth value" provides a rationale for the algorithm's
name.
Return value: void
Complexity:
Linear on average.
Notes:
All values in the range [randIterBegin,randIterNthVal)
will be less than (or equal to) all values in the range
[randIterValue,randIterEnd). Either or both ranges may be
sorted, but neither range is guaranteed to be.
- nth_element1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to partition a vector of integers of size 12
around its 7th element. The ranges on either side of this value
may or may not be sorted, but the algorithm does not guarantee
this, and you should not expect it.
template<class RandIterator>
void nth_element(RandIterator inputBegin,
RandIterator inputNthVal,
RandIterator inputEnd);
- nth_element(randIterBegin, randIterValue, randIterEnd,
binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value: void
Complexity:
Linear on average.
Notes:
All values in the range [randIterBegin,randIterNthVal)
will precede (according to the given order), or be equal to, all
values in the range [randIterValue,randIterEnd). Either or
both ranges may be ordered, but neither range is guaranteed to be.
- nth_element2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to partition a vector of integers of size 12
around its 7th element. The ranges on either side of this value
may or may not be sorted, but the algorithm does not guarantee
this, and you should not expect it. In this case the order of the
elements is determined by one integer preceding another if and
only if it has a smaller digit sum.
template<class RandIterator,
class BinaryPred>
void nth_element(RandIterator inputBegin,
RandIterator inputNthVal,
RandIterator inputEnd,
BinaryPred comparisonPred);
- partial_sort(randIterBegin, randIterSortedEnd, randIterEnd)
-
Action:
Partition the range [randIterBegin,randIterEnd) in such a
way that all values in the subrange
[randIterBegin,randIterSortedEnd) are less than or equal
to all values in the range [randIterSortedEnd,randIterEnd)
and the values in the range
[randIterBegin,randIterSortedEnd) are also sorted into
ascending order.
Return value: void
Complexity:
Somewhere between linear and n*log n.
Notes:
The values in the range [randIterSortedEnd,randIterEnd)
may also (by chance) be sorted, but it is unlikely.
- partial_sort1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to partially sort a vector of integers of
size 12 by getting its 5 smallest values into ascending order at
the beginning of the vector. The following range of values may
also be sorted (by chance), but the algorithm does not guarantee
this, and you should not expect it.
template<class RandIterator>
void partial_sort(RandIterator inputBegin,
RandIterator sortedEnd,
RandIterator inputEnd);
- partial_sort(randIterBegin, randIterSortedEnd, randIterEnd,
binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values and the
values in the range [randIterBegin,randIterSortedEnd) are
ordered according to the order determined by binPred.
Return value: void
Complexity:
Somewhere between linear and n*log n.
Notes:
The values in the range [randIterSortedEnd,randIterEnd)
may also (by chance) be sorted, but it is unlikely.
- partial_sort2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to partially order a vector of integers of
size 12 by moving the first 5 values in the given ordering to the
beginning of the vector, in the proper order. The range of values
following this value may also be ordered, but the algorithm does
not guarantee this, and you should not expect it. In this case
the order of the elements is determined by one integer preceding
another if and only if it has a smaller digit sum.
template<class RandIterator,
class BinaryPred>
void partial_sort(RandIterator inputBegin,
RandIterator inputNthVal,
RandIterator inputEnd,
BinaryPred comparisonPred);
- partial_sort_copy(inIterBegin, inIterEnd, randIterBegin,
randIterEnd)
-
Action:
Sort the range [inIterBegin,inIterEnd) and copy as much
as will fit into the range [randIterBegin,randIterEnd).
Return value:
An iterator pointing to the end of the output range, in this case
one position past the last copied value.
Complexity:
Somewhere between linear and n*log n.
Notes:
The output range may be smaller than the input range. The input
range is left unchanged.
- partial_sort_copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a range of values from a vector of
integers of size 12 into ascending order and copy as many of them
as will fit into a range within a second vector of integers. The
contents of the initial vector are unchanged by this action.
template<class InIterator,
class RandIterator>
RandIterator partial_sort_copy(InIterator inputBegin,
InIterator inputEnd,
RandIterator copiedOutputBegin,
RandIterator copiedOutputEnd);
- partial_sort_copy(inIterBegin, inIterEnd, randIterBegin,
randIterEnd, binPred)
-
Action:
Performs in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
An iterator pointing to the end of the output range, in this case
one position past the last copied value.
Complexity:
Somewhere between linear and n*log n.
Notes:
The output range may be smaller than the input range. The input
range is left unchanged.
- partial_sort_copy2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to order a range of values from a vector of
integers of size 12 into the order determined by increasing digit
sum, and copy as many of them as will fit into a range within a
second vector of integers. The contents of the initial vector are
unchanged by this action.
template<class InIterator,
class RandIterator,
class BinaryPred>
RandIterator partial_sort_copy(InIterator inputBegin,
InIterator inputEnd,
RandIterator beginCopiedOutput,
RandIterator endCopiedOutput,
BinaryPred comparisonPred);
- partial_sum(inIterBegin, inIterEnd, outIterBegin)
-
Action:
Fill the range starting at outIterBegin with a running
total of the values in the range [inIterBegin,inIterEnd).
That is, if x0, x1, x2, ... are
the first few values in the input sequence, and s0,
s1, s2, ... are the corresponding partial
sums in the output sequence written to the output range, then
s0=x0,
s1=s0+x1,
s2=s1+x2, ...
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The output range must be at least as large as the input range, and
may in fact be the input range.
- partial_sum1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the running totals of integer values
stored in a vector of integers and write those sums out to the
same vector of integers.
template<class InIterator,
class OutIterator>
OutIterator partial_sum(InIterator inputBegin,
InIterator inputEnd,
OutIterator result);
- partial_sum(inIterBegin, inIterEnd, outIterBegin, binFunc)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary function
binFunc replaces addition as the operator combining successive
values in the following way: if x0, x1,
x2, ... are the first few values in the input sequence,
and s0, s1, s2, ... are the
corresponding "partial sums" in the output sequence written to the
output range, then s0=x0,
s1=binFunc(s0,x1),
s2=binFunc(s1,x2), ...
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The output range must be at least as large as the input range, and
may in fact be the input range.
- partial_sum2a.cpp
| Windows_executable
| program_output
(text)
-
Illustrates how to find the "running totals" of integer values
stored in a vector of integers and computed using
newOutputValue = 2 * oldOutputValue + newInputValue
and to write those computed values out to the same vector of
integers.
template<class InIterator,
class OutIterator,
class BinaryFunc>
OutIterator partial_sum(InIterator inputBegin,
InIterator inputEnd,
OutIterator result,
BinaryFunc functor);
- partition(biIterBegin, biIterEnd, unPred)
-
Action:
Partition the range [biIterBegin,biIterEnd) by using a
predicate unPred. The values that satisfy unPred
will come before the values that do not.
Return value:
An iterator pointing to the first element for which the predicate
unPred is false, or to the end of the range if
all values in it satisfy unPred.
Complexity:
Linear in the size of the input range.
Notes: none
- partition1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to partition the integer values in a vector of
integers into two groups: those that are divisible by 3, and
those that are not.
template<class BiIterator,
class UnaryPred>
BiIterator partition(BiIterator inputBegin,
BiIterator inputEnd,
UnaryPred matchTestPred);
- pop_heap(randIterBegin, randIterEnd)
-
Action:
Pop the top (or root) value from the heap (a maximum heap, by
default). (In detail, this algorithm exchanges the values at
randIterBegin and randIterEnd-1, and then
rebuilds the heap with the values in the range
[randIterBegin,randIterEnd-1).
Return value: void
Complexity:
Logarithmic in the size of the input range.
Notes:
The value at randIterEnd-1, which is no longer part of
the heap, will nevertheless still be in the container
(vector or deque), unless it is explicitly removed. To understand
and make use of this algorithm you should already know what a heap
is and how it is represented in contiguous storage, or you should
look up this information elsewhere.
- pop_heap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to delete the top (root) (highest priority)
(largest) value from a (maximum) heap of integers.
template<class RandIterator>
void pop_heap(RandIterator inputBegin,
RandIterator inputEnd);
- pop_heap(randIterBegin, randIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred is used to determine the ordering of
values in the heap.
Return value: void
Complexity:
Logarithmic in the size of the input range.
Notes:
The value at randIterEnd-1, which is no longer part of
the heap, will nevertheless still be in the container
(vector or deque), unless it is explicitly removed. To understand
and make use of this algorithm you should already know what a heap
is and how it is represented in contiguous storage, or you should
look up this information elsewhere.
- pop_heap2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to delete the top (root) (highest priority)
(smallest) value from a (minimum) heap of integers.
template<class RandIterator,
class BinaryPred>
void pop_heap(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- prev_permutation(biIterBegin, biIterEnd)
-
Action:
Transform the sequence of values in the range
[biIterBegin,biIterEnd) into the next "smallest"
lexicographic permutation of those values, or, if that next
permutation does not exist, transform the sequence of values into
the lexicographically largest permutation of those values (i.e.,
sort the sequence to its last permutation).
Return value:
true if in fact there was a next permutation, and
otherwise false.
Complexity:
Linear in the size of the input range.
Notes:
The permutations are generated assuming a range of values sorted
in ascending order.
- prev_permutation1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to generate all permutations of a vector of
integers, in decreasing order, and also to demonstrate what
happens to the return value of the algorithm when the "end" of a
permutation sequence is reached and we then "roll over" to begin
a new sequence.
template<class BiIterator>
bool prev_permutation(BiIterator inputBegin,
BiIterator inputEnd);
- prev_permutation(biIterBegin, biIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the predicate
function binPred determines the order of values.
Return value:
true if in fact there was a next permutation, and
otherwise false.
Complexity:
Linear in the size of the input range.
Notes:
The permutations are generated assuming a range of values with an
order determined by binPred.
- prev_permutation2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to generate all permutations of a vector of
integers, in decreasing order, and also to demonstrate what
happens to the return value of the algorithm when the "end" of a
permutation sequence is reached and we then "roll over" to begin
a new sequence. In this case the order of the integers in a
permutation is determined by one integer preceding another if and
only if it has a larger digit sum.
template<class BiIterator,
class BinaryPred>
bool prev_permutation(BiIterator inputBegin,
BiIterator inputEnd,
BinaryPred comparisonPred);
- push_heap(randIterBegin, randIterEnd)
-
Action:
Insert a value into a heap. (In detail, this algorithm combines
the value at position randIterEnd-1 into the (already
existing) heap consisting of the values in the range
[randIterBegin,randIterEnd-1) to make a heap of all values
in the range [randIterBegin,randIterEnd).)
Return value: void
Complexity:
Logarithmic in the size of the input range.
Notes:
Before applying this algorithm, the programmer should make sure to
have a heap in the (vector or deque) container, and then add the
new element to the end of the container via the
push_back() member function. To understand and make use of
this algorithm you should already know what a heap is and how it is
represented in contiguous storage, or you should look up this
information elsewhere.
- push_heap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to add a value to a (maximum) heap of
integers.
template<class RandIterator>
void push_heap(RandIterator inputBegin,
RandIterator inputEnd);
- push_heap(randIterBegin, randIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred is used to determine the ordering of
values in the heap.
Return value: void
Complexity:
Logarithmic in the size of the input range.
Notes:
Before applying this algorithm, the programmer should make sure to
have a heap in the (vector or deque) container, and then add the
new element to the end of the container via the
push_back() member function. To understand and make use of
this algorithm you should already know what a heap is and how it is
represented in contiguous storage, or you should look up this
information elsewhere.
- push_heap2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to add a value to a (minimum) heap of
integers.
template<class RandIterator,
class BinaryPred>
void push_heap(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- random_shuffle(randIterBegin, randIterEnd)
-
Action:
Place the values in the range [randIterBegin,randIterEnd)
in pseudorandom order.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
This version of the algorithm uses a built-in pseudorandom number
generator.
- random_shuffle1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to randomize the order of values in a vector
of integers.
template<class RandIterator>
void random_shuffle(RandIterator inputBegin,
RandIterator inputEnd);
- random_shuffle(randIterBegin, randIterEnd, genFunc)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case genFunc is
used in generating the random sequence.
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
The generator function genFunc(num) must take an integer
argument and return a pseudorandom integer in the range
[0,num).
- random_shuffle2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to randomize the order of values in a vector
of integers, this time with the aid of a programmer-supplied
pseudorandom number generator.
template<class RandIterator,
class GeneratorFunc>
void random_shuffle(RandIterator inputBegin,
RandIterator inputEnd,
GeneratorFunc& genFunc);
- remove(forIterBegin, forIterEnd, val)
-
Action:
Remove from the range [forIterBegin,forIterEnd) all
values that are equal to val.
Return value:
An iterator pointing to the end of the range of remaining values.
Complexity:
Linear in the size of the input range.
Notes:
The algorithm is stable, in the sense that the relative order of
values that are not equal to val is preserved. However,
the algorithm does not behave in the way that you might expect. For
example, you might expect that after the values have been removed
the size of the input range would reflect this. But this is not the
case. The remaining values are grouped at the beginning of the
container (in their same order, because of the "stability"
mentioned above) but the size of the input range has not changed. Not
only this, the values at the end of the container are not even
(necessarily, at least) the removed values. In any case, when using
remove(), you should remember to adjust the size of the
container appropriately after the algorithm has finished.
- remove1a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to remove a given value from a vector of
integers and adjust the size of the vector appropriately after
the removal.
template<class ForIterator,
class T>
ForIterator remove(ForIterator inputBegin,
ForIterator inputEnd,
const T& valToRemove);
- remove_copy(inIterBegin, inIterEnd, outIterBegin, val)
-
Action:
Copy all values from the range [inIterBegin, inIterEnd),
except those equal to val, to an output range beginning at
outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The algorithm is stable, in the sense that the relative order of
values that are not equal to val is preserved in copying
them from the input range to the output range. The output range
should be at least as large as the input range.
- remove_copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to copy all values except a particular value
from one vector of integers to another.
template<class InIterator,
class OutIterator,
class T>
OutIterator remove_copy(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
const T& removedValue);
- remove_copy_if(inIterBegin, inIterEnd, outIterBegin, unPred)
-
Action:
Copy all values from the range [inIterBegin, inIterEnd),
except those for which the unary predicate unPred is
true, to an output range beginning at
outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The algorithm is stable, in the sense that the relative order of
values that do not satisfy unPred is preserved in copying
them from the input range to the output range. The output range
should be at least as large as the input range.
- remove_copy_if1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates ...
template<class InIterator,
class OutIterator,
class UnaryPred>
OutIterator remove_copy_if(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
UnaryPred matchTestPred);
- remove_if(forIterBegin, forIterEnd, unPred)
-
Action:
Remove from the range [forIterBegin,forIterEnd) all
values for which unPred is true.
Return value:
An iterator pointing to the end of the range of remaining values.
Complexity:
Linear in the size of the input range.
Notes:
The algorithm is stable, in the sense that the relative order of
values that are not removed is preserved. However,
the algorithm does not behave in the way that you might expect. For
example, you might expect that after the values have been removed
the size of the input range would reflect this. But this is not the
case. The remaining values are grouped at the beginning of the
container (in their same order, because of the "stability"
mentioned above) but the size of the input range has not changed. Not
only this, the values at the end of the container are not even
(necessarily, at least) the removed values. In any case, when using
remove_if(), you should remember to adjust the size of the
container appropriately after the algorithm has finished.
- remove_if1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to remove all values that are divisible by 3
from a vector of integers.
template<class ForIterator,
class UnaryPred>
ForIterator remove_if(ForIterator inputBegin,
ForIterator inputEnd,
UnaryPred matchTestPred);
- replace(forIterBegin, forIterEnd, oldVal, newVal)
-
Action:
Replace all values in the range [forIterBegin,forIterEnd)
that are equal to oldVal with newVal.
Return value: void
Complexity:
Linear in the size of the input range.
Notes: none
- replace1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to replace all copies of a given value from a
vector of integers with another value.
template<class ForIterator,
class T>
void replace(ForIterator inputBegin,
ForIterator inputEnd,
const T& oldVal,
const T& newVal);
- replace_copy(inIterBegin, inIterEnd, outIterBegin, oldVal,
newVal)
-
Action:
Copy the sequence [inIterBegin, inIterEnd) to a new
sequence beginning at outIterBegin, and simultaneously
replace all values that are equal to oldVal with
newVal in the output range.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes: none
- replace_copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to copy all values from one vector of
integers to another and simultaneously replace, in the output,
all instances of a given value with another value.
template<class InIterator,
class OutIterator,
class T>
OutIterator replace_copy(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
const T& oldVal,
const T& newVal);
- replace_copy_if(inIterBegin, inIterEnd, outIterBegin, unPred,
newVal)
-
Action:
Copy the values in the range [inIterBegin,inIterEnd) to
an output range beginning at outIterBegin, and replace all
the values (in the output container) where unPred is true
with newVal, and
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The output range must be at least as large as the input range.
- replace_copy_if1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to copy all values from one vector of
integers to another and simultaneously replace, in the output,
all values that satisfy a given predicate with a given alternate
value.
template<class InIterator,
class OutIterator,
class UnaryPred,
class T>
OutIterator replace_copy_if(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
UnaryPred matchTestPred,
const T& newVal);
- replace_if(forIterBegin, forIterEnd, unPred, newVal)
-
Action:
Replace all values in the range [forIterBegin,
forIterEnd) for which unPred is true with
newVal.
Return value: void
Complexity:
Linear in the size of the input range.
Notes: none
- replace_if1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to replace all copies of a given value in a
vector of integers that satisfy a given predicate with another
value.
template<class ForIterator,
class UnaryPred,
class T>
void replace_if(ForIterator inputBegin,
ForIterator inputEnd,
UnaryPred matchTestPred,
const T& newVal);
- reverse(biIterBegin, biIterEnd)
-
Action:
Reverses the order of all values in the range
[biIterBegin,biIterEnd).
Return value: void
Complexity:
Linear in the size of the input range.
Notes: none
- reverse1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to reverse the order of all, or just some, of
the values in a vector of integers.
template<class BiIterator>
void reverse(BiIterator inputBegin,
BiIterator inputEnd);
- reverse_copy(biIterBegin, biIterEnd, outIterBegin)
-
Action:
Copy the values in the range [biIterBegin, biIterEnd) to
an output range beginning at outIterBegin, and
simultaneously reverse the order of all values in the output range.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The output range must be at least as large as the input range.
- reverse_copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to reverse the order of all, or just some, of
the values in a vector of integers while copying the values to an
output range in another vector of integers.
template<class BiIterator,
class OutIterator>
OutIterator reverse_copy(BiIterator inputBegin,
BiIterator inputEnd,
OutIterator outputBegin);
- rotate(forIterBegin, forIterIntermediate, forIterEnd)
-
Action:
Rotate the values in the range [biIterBegin,biIterEnd) so
that the value pointed to by forIterIntermediate becomes
the new first value.
Return value: void
Complexity:
Linear in the size of the input range.
Notes: none
- rotate1a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to rotate the order of all, or just some, of
the values in a vector of integers.
template<class ForIterator>
void rotate(ForIterator inputBegin,
ForIterator inputIntermediate,
ForIterator inputEnd);
- rotate_copy(forIterBegin, forIterIntermediate, forIterEnd,
outIterBegin)
-
Action:
Copy the values from the range [forIterBegin,forIterEnd)
to an output range beginning at outIterBegin, and
simultaneously rotate all the values in the output range so that
the value pointed to by forIterIntermediate becomes the
new first value.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes:
The output range must be at least as large as the input range.
- rotate_copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to rotate the order of all, or just some, of
the values in a vector of integers while copying the values to an
output range in another vector of integers.
template<class ForIterator,
class OutIterator>
OutIterator rotate_copy(ForIterator inputBegin,
ForIterator inputIntermediate,
ForIterator inputEnd,
OutIterator outputBegin);
- search(forIter1Begin, forIter1End, forIterBegin2,
forIterEnd2)
-
Action:
Search for the first occurrence of the range of values given by
[forIter2Begin,forIter2End) within the range of values
given by [forIter1Begin,forIter1End).
Return value:
An iterator pointing to the first value of the matching range
within [forIter1Begin,forIter1End) if such a matching
range is found, and to forIter1End if there is no matching
range.
Complexity:
Linear in the size of the input range.
Notes:
For a "matching range" to exist, corresponding values in the
ranges must be equal.
- search1a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to find the first occurrence of one range of
integer values in a vector within another range of integer values
in a vector.
template<class ForIterator1,
class ForIterator2>
ForIterator1 search(ForIterator1 searchRangeBegin,
ForIterator1 searchRangeEnd,
ForIterator2 targetRangeBegin,
ForIterator2 targetRangeEnd);
- search(forIter1Begin, forIter1End, forIterBegin2, forIterEnd2,
binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the test applied to
corresponding elements to determine if the ranges match is
performed by binPred.
Return value:
An iterator pointing to the first value of the matching range
within [forIter1Begin,forIter1End) if such a matching
range is found, and to forIter1End if there is no matching
range.
Complexity:
Linear in the size of the input range.
Notes:
For a "matching range" to exist, binPred applied to
corresponding values from the two ranges must return true.
- search2a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to find the first occurrence of one range of
integer values in a vector within another range of integer values
in a vector, and for which corresponding values in the two ranges
match if and only if they have the same digit sum.
template<class ForIterator1,
class ForIterator2,
class BinaryPred>
ForIterator1 search(ForIterator1 searchRangeBegin,
ForIterator1 searchRangeEnd,
ForIterator2 targetRangeBegin,
ForIterator2 targetRangeEnd,
BinaryPred matchTestPred);
- search_n(forIterBegin, forIterEnd, num, val)
-
Action:
Search in the range [forIterBegin,forIterEnd) for a
subsequence of num consecutive values each equal to
val.
Return value:
An iterator pointing to the first value of the found subsequence,
or to forIterEnd if no such subsequence is found.
Complexity:
Linear in the size of the input range.
Notes: none
- search_n1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find instances of a consecutive sequence
of identical values in a vector of integers.
template<class ForIterator,
class size_type,
class T>
ForIterator search_n(ForIterator inputBegin,
ForIterator inputEnd,
size_type num,
const T& val);
- search_n(forIterBegin, forIterEnd, i, val, binPred)
-
Action:
Performs in a manner analogous to the previous version of the
algorithm given above, except that in this case each of the
consecutive values containerVal from the input range must
satisfy binPred(val,containerVal) == true.
Return value:
An iterator pointing to the first value of the found subsequence,
or to forIterEnd if no such subsequence is found.
Complexity:
Linear in the size of the input range.
Notes: none
- search_n2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find instances of a consecutive sequence
of matching values in a vector of integers, where values match if
and only if they have the same digit sum.
template<class ForIterator,
class size_type,
class T,
class BinaryPred>
ForIterator search_n(ForIterator inputBegin,
ForIterator inputEnd,
size_type num,
const T& val,
BinaryPred matchTestPred);
- set_difference(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, outIterBegin)
-
Action:
Create a set of values that are in the range
[inIter1Begin,inIter1End) but are not in the range
[inIter2Begin,inIter2End), and write the values out to a
range beginning at outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the "difference"
operation from mathematical set theory, with (excuse the pun) some
differences. First, the values in both input ranges must be sorted
in ascending order, and the output range will be similarly sorted
as well. The output range must be at least as large as the input
range. Duplicates in the output are possible, since the number of
times a value appears in the output is the number of times it
appears in the first range minus the number of times it appears in
the second, as long as this is a nonnegative number. If this number
is negative (implying the number of equal values is greater is the
second range), the given element will not appear in the output.
- set_difference1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers but not in a second vector of integers, and write
them out to a third vector of integers.
template<class InIterator1,
class InIterator2,
class OutIterator>
OutIterator set_difference(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator outputBegin);
- set_difference(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, outIterBegin, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred is used as the sorting criterion.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the "difference"
operation from mathematical set theory, with (excuse the pun) some
differences. First, the values in both input ranges must be ordered
according to the order determined by binPred, and the
output range will be similarly ordered as well. The output range
must be at least as large as the input range. Duplicates in the
output are possible, since the number of times a value appears in
the output is the number of times it appears in the first range
minus the number of times it appears in the second, as long as this
is a nonnegative number. If this number is negative (implying the
number of equal values is greater is the second range), the given
element will not appear in the output.
- set_difference2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers but not in a second vector of integers, and write
them out to a third vector of integers. In this case the vectors
are ordered in the sense that one integer comes before another if
and only if it has a smaller digit sum.
template<class InIterator1,
class InIterator2,
class OutIterator,
class BinaryPred>
OutIterator set_difference(InIterator1 input1Begin,
InIterator1 input1End,
InIterator2 input2Begin,
InIterator2 input2End,
OutIterator outputBegin,
BinaryPred comparisonPred);
- set_intersection(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, outIterBegin)
-
Action:
Create a set of values that are in the range
[inIter1Begin,inIter1End) and also in the range
[inIter2Begin,inIter2End), and write the values out to a
range beginning at outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the "intersection"
operation from mathematical set theory, with some differences.
First, the values in both input ranges must be sorted in ascending
order, and the output range will be similarly sorted as well. The
output range must be at least as large as the input range.
Duplicates in the output are possible, if a value appears more than
once in both input ranges. The number of times it appears in the
output is then the minimum number of times it appears in the two
input ranges.
- set_intersection1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers and also in a second vector of integers, and write
them out to a third vector of integers.
template<class InIterator1,
class InIterator2,
class OutIterator>
OutIterator set_intersection(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator outputBegin);
- set_intersection(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, outIterBegin, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred is used as the sorting criterion.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the "intersection"
operation from mathematical set theory, with some differences.
First, the values in both input ranges must be ordered according to
the order determined by binPred, and the output range will
be similarly ordered as well. The output range must be at least as
large as the input range. Duplicates in the output are possible, if
equal values according to the ordering criterion appear more than
once in both ranges. The number of times such a value appears in
the output is then the minimum number of times it appears in the two
input ranges.
- set_intersection2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers and also in a second vector of integers, and write
them out to a third vector of integers. In this case the vectors
are ordered in the sense that one integer comes before another if
and only if it has a smaller digit sum.
template<class InIterator1,
class InIterator2,
class OutIterator,
class BinaryPred>
OutIterator set_intersection(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator outputBegin,
BinaryPred comparisonPred);
- set_symmetric_difference(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, outIterBegin)
-
Action:
Create a set of elements that are not in both sequences
[inIter1Begin,inIter1End) and
[inIter2Begin,inIter2End) (i.e., that are in one or the
other of the two sequences but not in both), and write them out to
a range beginning at outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the
"symmetric_difference" operation from mathematical set theory, with
some differences. First, the values in both input ranges must be
sorted in ascending order, and the output range will be similarly
sorted as well. The output range must be at least as large as the
input range. Duplicates in the output are possible, if a value
appears more times in one of the input ranges than in the other.
- set_symmetric_difference1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers but not in a second vector of integers, as well as
those integers that are in the second vector but not in the
first, and write them out to a third vector of integers.
template<class InIterator1,
class InIterator2,
class OutIterator>
OutIterator set_symmetric_difference(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator outputBegin);
- set_symmetric_difference(inIter1Begin, inIter1End, inIter2Begin,
inIter2End, outIterBegin, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred is used as the sorting criterion.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the
"symmetric_difference" operation from mathematical set theory, with
some differences. First, the values in both input ranges must be
ordered according to the order determined by binPred, and
the output range will be similarly ordered as well. The output
range must be at least as large as the input range. Duplicates in
the output are possible, if a value appears more times in one of
the input ranges than in the other.
- set_symmetric_difference2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers but not in a second vector of integers, as well as
those integers that are in the second vector but not in the
first, and write them out to a third vector of integers. In this
case the vectors are ordered in the sense that one integer comes
before another if and only if it has a smaller digit sum.
template<class InIterator1,
class InIterator2,
class OutIterator,
class BinaryPred>
OutIterator set_symmetric_difference(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator outputBegin,
BinaryPred comparisonPred);
- set_union(inIter1Begin, inIter1End, inIter2Begin, inIter2End,
outIterBegin)
-
Action:
Create a set of values that are in either the range
[inIter1Begin,inIter1End) or in the range
[inIter2Begin,inIter2End) (or in both), and and write them
out to a range beginning at outIterBegin.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the "union" operation
from mathematical set theory, with some differences. First, the
values in both input ranges must be sorted in ascending order, and
the output range will be similarly sorted as well. The output range
must be at least as large as the input range. Duplicates in the
output are possible; the number of times a value that appear in
both input ranges appears in the output range is the maximum number
of times it appears in either of the two input ranges.
- set_union1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers or in a second vector of integers (or in both), and
write them out to a third vector of integers.
template<class InIterator1,
class InIterator2,
class OutIterator>
OutIterator set_union(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator ouputBegin);
- set_union(inIter1Begin, inIter1End, inIter2Begin, inIter2End,
outIterResult, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the binary
predicate binPred is used as the sorting criterion.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the sum of the input range sizes.
Notes:
Note that this algorithm "kind of" performs the "union" operation
from mathematical set theory, with some differences. First, the
values in both input ranges must be ordered according to the order
determined by binPred, and the output range will be
similarly ordered as well. The output range must be at least as
large as the input range. Duplicates in the output are possible;
the number of times a value that appear in both input ranges
appears in the output range is the maximum number of times it
appears in either of the two input ranges.
- set_union2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the values that are in a first vector
of integers or in a second vector of integers (or in both), and
write them out to a third vector of integers. In this case the
vectors are ordered in the sense that one integer comes before
another if and only if it has a smaller digit sum.
template<class InIterator1,
class InIterator2,
class OutIterator,
class BinaryPred>
OutIterator set_union(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
InIterator2 inputEnd2,
OutIterator result,
BinaryPred comparisonPred);
- sort(randIterBegin, randIterEnd)
-
Action:
Sort, in place, into ascending order, the values in the range
[randIterBegin,randIterEnd).
Return value: void
Complexity:
n*log n on average, where n is the size of the input range.
Notes:
operator< must be defined for the values in the range
to be sorted.
- sort1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a vector of integers into ascending
order.
template<class RandIterator>
void sort(RandIterator inputBegin,
RandIterator inputEnd);
- sort(randIterBegin, randIterEnd, binPred)
-
Action:
Sort, in place, the values in the range
[randIterBegin,randIterEnd), using binPred to
determine when one value in the range precedes another.
Return value: void
Complexity:
n*log n on average, where n is the size of the input range.
Notes:
When the values in the range
[randIterBegin,randIterEnd)are being sorted, a value
val1 precedes a value val2 if and only if
binPred(val1,val2) returns true.
- sort2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a vector of integers, when a first
integer comes before a second if and only if the first has a
smaller digit sum than the second.
- sort2b.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a vector of integers into descending
order by using a built-in function object to change the default
order used by the sort() algorithm.
template<class RandIterator,
class BinaryPred>
void sort(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- sort_heap(randIterBegin, randIterEnd)
-
Action:
Convert, in place, an already existing heap within the range
[randIterBegin,randIterEnd) into a sequence sorted in
ascending order.
Return value: void
Complexity:
n*log n, where n is the size of the input range.
Notes:
In this case operator< is used to determine when one
value precedes another.
- sort_heap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a maximum heap of integers stored
in a vector into ascending order.
template<class RandIterator>
void sort_heap(RandIterator inputBegin,
RandIterator inputEnd);
- sort_heap(randIterBegin, randIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the comparison
function binPred is used to determine when one value
precedes another.
Return value: void
Complexity:
n*log n, where n is the size of the input range.
Notes:
In this case val1 precedes val2 if and only if
binPred(val1,val2) returns true.
- sort_heap2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a minimum heap of integers stored
in a vector into descending order.
template<class RandIterator,
class BinaryPred>
void sort_heap(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- stable_partition(biIterBegin, biIterEnd, unPred)
-
Action:
Partition the values in the range [biIterBegin,biIterEnd)
by using the unary predicate unPred in such a way that the
values that satisfy unPred come before the values that do
not satisfy the predicate.
Return value:
An iterator pointing to the first value for which unPred
is false, or to the end of the input range if there is no
such value.
Complexity:
Linear in the size of the input range if enough memory is available;
otherwise n*log n where n is the size of the input range.
Notes:
This algorithm performs in a manner analogous to
partition(), except that the partitioning is stable, which
means that the algorithm is guaranteed to preserve the relative
order of values within each part of the partition.
- stable_partition1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates ...
template<class BiIterator,
class UnaryPred>
ForIterator stable_partition(BiIterator inputBegin,
BiIterator inputEnd,
UnaryPred matchTest);
- stable_sort(randIterBegin, randIterEnd)
-
Action:
Sort, in place, into ascending order, the values in the range
[randIterBegin,randIterEnd), using a stable sort.
Return value: void
Complexity:
n*log n, where n is the size of the input range, if there is enough
memory, otherwise n*log n * log n.
Notes:
This algorithm performs in a manner analogous to sort(),
except that in this case the sort is stable, which means that the
algorithm is guaranteed to preserve the relative order of equal
values.
- stable_sort1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort Points, where one Point comes
before another if and only if its x-coordinate is less than
the x-coordinate of the second Point.
template<class RandIterator>
void stable_sort(RandIterator inputBegin,
RandIterator inputEnd);
- stable_sort(randIterBegin, randIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version of the
algorithm given above, except that in this case the comparison
function binPred is used to determine when one value
precedes another.
Return value: void
Complexity:
n*log n, where n is the size of the input range, if there is enough
memory, otherwise n*log n * log n.
Notes:
In this case val1 precedes val2 if and only if
binPred(val1,val2) returns true.
- stable_sort2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to sort a vector of integers, when a first
integer comes before a second if and only if the first has a
smaller digit sum than the second, and in such a way that
duplicate values retain their relative positions.
template<class RandIterator,
class BinaryPred>
void stable_sort(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- swap(val1, val2)
-
Action:
Exchange the values in val1 and val2.
Return value: void
Complexity:
Constant time.
Notes: none
- swap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to swap integer values, double values, and
string values in simple variables. It also illustrates the
swapping of integer values in a vector, using three different
ways to access the values.
template<class T>
void swap(T& val1,
T& val2);
- swap_ranges(forIter1Begin, forIter1End, forIter2Begin)
-
Action:
Swap each value in the range [forIter1Begin,forIter1End)
with the corresponding value in the range beginning at
forIter2Begin.
Return value:
An iterator pointing to the end of the second range (the one
that started at forIter2Begin).
Complexity:
Linear in the size of the input range.
Notes: The range of values beginning at
forIter2Begin must be at least as large as the range of values
given by [forIter1Begin,forIter1End).
- swap_ranges1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to swap the values in a range of integers
within a vector of integers with the values in a range of integers
within a deque of integers.
template<class ForIterator1,
class ForIterator2>
ForIterator2 swap_ranges(ForIterator1 input1Begin,
ForIterator1 input1End,
ForIterator2 input2Begin);
- transform(inIterBegin, inIterEnd, outIterBegin, unFunc)
-
Action:
Transform the range [inIterBegin,inIterEnd) into a range
beginning at outIterBegin by applying a unary function
unFunc. This function takes the current element as a
parameter and returns the "transformed value".
Return value:
An iterator pointing to the end of the transformed range.
Complexity:
Linear in the size of the input range.
Notes:
The first and third parameters (inIterBegin and
outIterBegin) can be the same, which means that the
input is modified.
- transform1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the square root of each
value in a range of integers, as well as the cube of each
value in a range of integers. The square roots are found with
a built-in library function and placed in a different container
from the original values. The cubes are found with a
programmer-defined function and they overwrite the original
values.
template<class InIterator,
class OutIterator,
class UnaryFunc>
OutIterator transform(InIterator inputBegin,
InIterator inputEnd,
OutIterator outIterBegin,
UnaryFunc unFunc);
- transform(inIter1Begin, inIter1End, inIter2Begin, outIterBegin,
binFunc)
-
Action:
Perform in a manner analogous to the previous version, except
that in this case the binary function binFunc is used
instead of a unary function. This binary function takes the current
element of the first range [inIter1Begin,inIter1End) as
its first parameter, and the corresponding element from the second
range as its second parameter, and again returns the "transformed
value".
Return value:
An iterator pointing to the end of the transformed range.
Complexity:
Linear in the size of the input range.
Notes:
The first and third parameters (inIterBegin and
outIterBegin) can be the same, which means that the
input is modified.
- transform2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to multiply the values in a range of integers
from a vector with corresponding values in a range of integers from
a deque and write the products to a range within a list of
integers.
template<class InIterator1,
class InIterator2,
class OutIterator,
class BinaryFunc>
OutIterator transform(InIterator1 inputBegin1,
InIterator1 inputEnd1,
InIterator2 inputBegin2,
OutIterator outIterBegin,
BinaryFunc binFunc);
- unique(forIterBegin, forIterEnd)
-
Action:
Collapse any instance of consecutive duplicate values in the
range [forIterBegin,forIterEnd) to a single value.
Return value:
An iterator pointing to the end of the collapsed range.
Complexity:
Linear in the size of the input range.
Notes:
The algorithm is stable, meaning that the relative order of the
values that are not removed is preserved. Also, it is up to
the caller of this algorithm to use the "new end" of the
range of the remaining values rather than the "old end";
that is, the size of the input range is not adjusted to reflect
a decrease due to removed values. [See also the remove() and
remove_if() algorithms.]
- unique1a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to remove adjacent duplicate copies of
integer values from a vector of integers.
template<class ForIterator>
ForIterator unique(ForIterator inputBegin,
ForIterator inputEnd);
- unique(forIterBegin, forIterEnd, binPred)
-
Action:
Perform in a manner analogous to the previous version, except
that in this case the binary predicate binPred determines
when values are duplicates.
Return value:
An iterator pointing to the end of the collapsed range.
Complexity:
Linear in the size of the input range.
Notes:
The algorithm is stable, meaning that the relative order of the
values that are not removed is preserved. Also, it is up to
the caller of this algorithm to use the "new end" of the
range of the remaining values rather than the "old end";
that is, the size of the input range is not adjusted to reflect
a decrease due to removed values.
- unique2a.cpp |
Windows_executable
| program_output
(text)
- Illustrates how to remove adjacent duplicate copies of integer
values divisible by 3 from a vector of integers.
template<class ForIterator,
class BinaryPred>
ForIterator unique(ForIterator inputBegin,
ForIterator inputEnd,
BinaryPred matchTest);
- unique_copy(inIterBegin, inIterEnd, outIterBegin)
-
Action:
Copy the sequence [inIterBegin,inIterEnd) to a new
sequence beginning at outIterBegin, except that in any
consecutive group of duplicate values only the first one is copied.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes: The range of values beginning at
outIterBegin must be at least as large at the range given by
[inIterBegin,inIterEnd).
- unique_copy1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to remove adjacent duplicate copies of
integer values from a vector of integers, and simultaneously
copy the remaining values to another vector.
template<class InIterator,
class OutIterator>
OutIterator unique_copy(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin);
- unique_copy(inIterBegin, inIterEnd, outIterBegin, binPred)
-
Action:
Perform in a manner analogous to the previous version, except
that in this case the binary predicate binPred determines
when values are duplicates.
Return value:
An iterator pointing to the end of the output range.
Complexity:
Linear in the size of the input range.
Notes: The range of values beginning at
outIterBegin must be at least as large at the range given by
[inIterBegin,inIterEnd).
- unique_copy2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to remove adjacent duplicate copies of
integer values divisible by 3 from a vector of integers, and
simultaneously copy the remaining values to another vector.
template<class InIterator,
class OutIterator,
class BinaryPred>
OutIterator unique_copy(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
BinaryPred matchTest);
- upper_bound(forIterBegin, forIterEnd, val)
-
Action:
Find the upper bound of val within the range
[forIterBegin,forIterEnd), i.e., the first value in
the range that is greater than val.
Return value:
An iterator pointing to the upper bound, or to forIterEnd
if the upper bound does not exist.
Complexity:
Logarithmic in the size of the input range for random access iterators,
otherwise linear.
Notes: none
- upper_bound1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates ...
template<class ForIterator,
class T>
ForIterator upper_bound(ForIterator inputBegin,
ForIterator inputEnd,
const T& targetValue);
- upper_bound(forIterBegin, forIterEnd, val, binPred)
-
Action:
Perform in a manner analogous to the previous version, except
that in this case the binary predicate binPred determines
when one element comes before another.
Return value:
An iterator pointing to the upper bound, or to forIterEnd
if the upper bound does not exist.
Complexity:
Logarithmic in the size of the input range for random access iterators,
otherwise linear.
Notes:
In this case val1 precedes val2 if and only if
binPred(val1,val2) returns true.
- upper_bound2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how
template<class ForIterator,
class T,
class BinaryPred>
ForIterator upper_bound(ForIterator inputBegin,
ForIterator inputEnd,
const T& val,
BinaryPred comparisonPred);
- all_of(inIterBegin, inIterEnd, unPred)
-
Action:
Determines whether all elements in the range
[inIterBegin, inIterEnd) satisfy the unary predicate
unPred.
Return value:
true if all values do satisfy the predicate, false
otherwise.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- all_of1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether a vector of integers are
all even.
template<class InIterator,
class UnaryPred>
bool all_of(InIterator inputBegin,
InIterator inputEnd,
UnaryPred matchTestPred);
- any_of(inIterBegin, inIterEnd, unPred)
-
Action:
Determines whether any element in the range
[inIterBegin, inIterEnd) satisfies the unary predicate
unPred.
Return value:
true if any value does satisfy the predicate, false
otherwise.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- any_of1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether a vector of integers contains
an odd integer.
template<class InIterator,
class UnaryPred>
bool any_of(InIterator inputBegin,
InIterator inputEnd,
UnaryPred matchTestPred);
- copy_if(inIterBegin, inIterEnd, outIterBegin, unPred)
-
Action:
Copies all elements from the source range
[inIterBegin, inIterEnd) that satisfy the unary predicate
unPred to the output range, starting at outIterBegin.
Return value:
An iterator pointing to the end (one-past-the-last) of the copied
range in the destination container.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range. The
destination range must be big enough to hold the elements being
copied.
- copy_if1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to copy all negative integers from a vector
of integers to a deque of integers.
template<class OutIterator,
class UnaryPred>
bool any_of(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin,
UnaryPred matchTestPred);
- copy_n(inIterBegin, num, outIterBegin)
-
Action:
Copies num elements from the input range, starting at
inIterBegin to the output range, starting at
outIterBegin.
Return value:
An iterator pointing to the end (one-past-the-last) of the output
range in the destination container (i.e., pointing to the first
element that is not overwritten, or to end()).
Complexity:
Linear in the size of the input range.
Notes:
The destination range must be big enough to hold the elements
being copied.
- copy_n1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to copy the first four integers from a vector
of ten integers to a deque of five integers.
template<class OutIterator,
class Size,
class UnaryPred>
OutIterator copy_n(InIterator inputBegin,
Size numElementsToCopy,
OutIterator outputBegin);
- find_if_not(inIterBegin, inIterEnd, unPred)
-
Action:
Finds the first element from the input range
[inIterBegin, inIterEnd) for which the unary predicate
unPred is not satisfied.
Return value:
An iterator pointing to that first value for which the unary predicate
is false, or to inIterEnd.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- find_if_not1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to copy all negative integers from a vector
template<class InIterator,
class UnaryPred>
bool find_if_not(InIterator inputBegin,
InIterator inputEnd,
UnaryPred matchTestPred);
- iota(forIterBegin, forIterEnd, val)
-
Action:
Writes the values val, val+1, val+2,
... to the locations specified by
[inIterBegin, inIterEnd).
Return value: void
Complexity:
Linear in the size of the input range.
Notes:
Incrementing val must make sense.
- iota1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether a vector of integers contains
no odd integers.
template<class ForIterator,
class T>
void iota(ForIterator inputBegin,
ForIterator inputEnd,
T startValue);
- is_heap(randIterBegin, randIterEnd)
-
Action:
Determines whether the values in the range
[randIterBegin,randIterEnd) are a maximum heap.
Return value:
true if the values are in fact a maximum heap, otherwise
false.
Complexity:
Linear in the size of the input range.
Notes:
operator< must be defined for the values in the range
to be tested.
- is_heap1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test a vector of integers to see if it is
a maximum heap.
template<class RandIterator>
bool is_heap(RandIterator inputBegin,
RandIterator inputEnd);
- is_heap(randIterBegin, randIterEnd, binPred)
-
Action:
Determines whether the values in the range
[randIterBegin,randIterEnd) are a heap, using binPred
to determine when one value in the range precedes another.
Return value:
true if the values are a heap based on the order given by
binPred, otherwise false.
Complexity:
Linear in the size of the input range.
Notes:
When the values in the range
[randIterBegin,randIterEnd)are being compared, a value
val1 precedes a value val2 if and only if
binPred(val1,val2) returns true.
- is_heap2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test a vector of integers to see if it is
minimum heap.
template<class RandIterator,
class BinaryPred>
bool is_heap(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- is_heap_until(randIterBegin, randIterEnd)
-
Action:
Returns an iterator pointing to the first element that destroys the
sorting of the range [randIterBegin,randIterEnd) as a
maximum heap (i.e., the first element that is larger than the first
element of that range) or pointing to randIterEnd if there
is no such element.
Return value:
An iterator as described above.
Complexity:
Linear in the size of the input range.
Notes:
operator< must be defined for the values in the range
to be tested.
- is_heap_until1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the first integer in a vector of integers
that destroys the sorting of the vector as a maximum heap.
template<class RandIterator>
RandIterator is_heap_until(RandIterator inputBegin,
RandIterator inputEnd);
- is_heap_until(randIterBegin, randIterEnd, binPred)
-
Action:
Returns an iterator pointing to the first element that destroys the
sorting of the range [randIterBegin,randIterEnd) as a
heap (i.e., the first element that is "more optimal" than the first
element of that range according to the order determined by
binPred) or pointing to randIterEnd if there
is no such element.
Return value:
An iterator as described above.
Complexity:
Linear in the size of the input range.
Notes:
When the values in the range
[randIterBegin,randIterEnd)are being compared, a value
val1 precedes a value val2 if and only if
binPred(val1,val2) returns true.
- is_heap_until2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the first integer in a vector of integers
that destroys the sorting of the vector as a minimum heap.
template<class RandIterator,
class BinaryPred>
RandIterator is_heap_until(RandIterator inputBegin,
RandIterator inputEnd,
BinaryPred comparisonPred);
- is_partitioned(inIterBegin, inIterEnd, unPred)
-
Action:
Determines whether the elements in the range
[inIterBegin, inIterEnd) are partitioned in the sense that
all elements that satisfy the unary predicate unPred come
before those that do not.
Return value:
true if the elements are partitioned, false
otherwise.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- is_partitioned1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether a vector of integers is
partitioned with all odd integers preceeding all even integers.
template<class InIterator,
class UnaryPred>
bool is_partitioned(InIterator inputBegin,
InIterator inputEnd,
UnaryPred matchTestPred);
- is_permutation(forIterBegin1, forIterEnd1, forIterBegin2)
-
Action:
Determines whether the elements in the range
[forIterBegin1,forIterEnd1) are a permutation of the elements
in the range starting at forIterBegin2.
Return value:
true if the elements are a permutation, false
otherwise.
Complexity:
Quadratic at worst.
Notes:
Compares elements using operator==.
- is_permutation1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether the elements in one vector
of integers are a permutation of some (or all of) the integers in a
second vector of integers.
template<class ForIterator1,
class ForIterator2>
bool is_permutation(ForIterator1 inputBegin1,
ForIterator1 inputEnd1,
ForIterator2 inputBegin2);
- is_permutation(forIterBegin1, forIterEnd1, forIterBegin2, binPred)
-
Action:
Determines whether the elements in the range
[forIterBegin1,forIterEnd1) are a permutation of the elements
in the range starting at forIterBegin2.
Return value:
true if the elements are a permutation, false
otherwise.
Complexity:
Quadratic at worst.
Notes:
Compares elements using binPred.
- is_permutation1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether ...
template<class ForIterator1,
class ForIterator2>
bool is_permutation(ForIterator1 inputBegin1,
ForIterator1 inputEnd1,
ForIterator2 inputBegin2
BinaryPred comparisonPred);
- is_sorted(forIterBegin, forIterEnd)
-
Action:
Determines whether the values in the range
[forIterBegin,forIterEnd) are sorted into ascending order.
Return value:
true if the values are sorted in ascending order, otherwise
false.
Complexity:
Linear in the size of the input range.
Notes:
operator< must be defined for the values in the range
to be tested.
- is_sorted1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test a vector of integers to see if it is
sorted in ascending order.
template<class ForIterator>
bool is_sorted(ForIterator inputBegin,
ForIterator inputEnd);
- is_sorted(forIterBegin, forIterEnd, binPred)
-
Action:
Determines whether the values in the range
[forIterBegin,forIterEnd) are sorted, using binPred
to determine when one value in the range precedes another.
Return value:
true if the values are sorted in the specified order,
otherwise false.
Complexity:
Linear in the size of the input range.
Notes:
When the values in the range
[forIterBegin,forIterEnd)are being sorted, a value
val1 precedes a value val2 if and only if
binPred(val1,val2) returns true.
- is_sorted2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to test a vector of integers to see if it is
sorted in descending order.
template<class ForIterator,
class BinaryPred>
bool is_sorted(ForIterator inputBegin,
ForIterator inputEnd,
BinaryPred comparisonPred);
- is_sorted_until(forIterBegin, forIterEnd)
-
Action:
Returns a ForwardIterator pointing to the first element in
the range [forIterBegin,forIterEnd) which destroys the
sorting (into ascending order) of the range, or to forIterEnd
if the range is in fact sorted.
Return value:
An iterator pointing at the first sort-destroying element, or at
forIterEnd if the range is sorted.
Complexity:
Linear in the size of the input range.
Notes:
operator< must be defined for the values in the range
to be tested.
- is_sorted_until1a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the first (if any) value in a vector of
integers that destroys the sort of the vector into ascending order.
template<class ForIterator>
bool is_sorted_until(ForIterator inputBegin,
ForIterator inputEnd);
- is_sorted_until(forIterBegin, forIterEnd, binPred)
-
Action:
Returns a ForwardIterator pointing to the first element in
the range [forIterBegin,forIterEnd) which destroys the
sorting, where the sorting order is determined using binPred
to determine when one value in the range precedes another.
Return value:
An iterator pointing at the first sort-destroying element, or at
forIterEnd if the range is sorted.
Complexity:
Linear in the size of the input range.
Notes:
When the values in the range
[forIterBegin,forIterEnd)are being sorted, a value
val1 precedes a value val2 if and only if
binPred(val1,val2) returns true.
- is_sorted_until2a.cpp
| Windows_executable
| program_output
(text)
- Illustrates how to find the first (if any) value in a vector of
integers that destroys the sort of the vector into descending order.
template<class ForIterator,
class BinaryPred>
bool is_sorted_until(ForIterator inputBegin,
ForIterator inputEnd,
BinaryPred comparisonPred);
- minmax(val1, val2)
-
Action:
Returns a pair in which the first component is the minimum
value input and the second component is the maximum value input.
Return value:
A pair object as described above.
Complexity:
Constant.
Notes:
Compares elements using operator<. May also take an
initializer list as input.
- minmax1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine the minimum and maximum of ...
template<class T>
pair<const T&, const T&> minmax(const T& val1,
const T& val2);
- minmax(val1, val2, binPred)
-
Action:
Returns a pair in which the first component is the minimum
value input and the second component is the maximum value input.
Return value:
A pair object as described above.
Complexity:
Constant.
Notes:
Compares elements using binPred. May also take an initializer
list as input.
- minmax1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether ...
template<class T,
class BinaryPred>
pair<const T&, const T&> minmax(const T& val1,
const T& val2,
BinaryPred comparisonPred);
- minmax_element(forIterBegin, forIterEnd)
-
Action:
Returns a pair in which the first component is an iterator pointing
to the minimum element in the range [forIterBegin,forIterEnd),
and the second component is an iterator pointing at the maximum element
in that range.
Return value:
A pair as described above.
Complexity:
Linear in the size of the input range.
Notes:
Compares elements using operator==.
- minmax_element1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine ...
template<class ForIterator>
bool minmax_element(ForIterator inputBegin,
ForIterator inputEnd);
- minmax_element(forIterBegin, forIterEnd, binPred)
-
Action:
Returns a pair in which the first component is an iterator pointing
to the minimum element in the range [forIterBegin,forIterEnd),
and the second component is an iterator pointing at the maximum element
in that range.
Return value:
A pair as described above.
Complexity:
Linear in the size of the input range.
Notes:
Compares elements using binPred.
- minmax_element1b.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine ...
template<class ForIterator>
bool minmax_element(ForIterator inputBegin,
ForIterator inputEnd,
BinaryPred comparisonPred);
- move(inIterBegin, inIterEnd, outIterBegin)
-
Action:
Moves all elements in the source range [inIterBegin,inIterEnd)
into the destination range, starting at outIterBegin.
Return value:
An iterator pointing at the position after the last moved element (the
first one not overwritten).
Complexity:
Linear in the size of the source range.
Notes:
Copies elements if the type of the element does not support move
semantics. The destination range must be large enough to receive the
moved elements, or insert iterators must be used.
- move1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to ...
template<class InIterator,
class OutIterator>
OutIterator move(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputBegin);
- move_backward(inIterBegin, inIterEnd, outIterEnd)
-
Action:
Moves all elements in the source range [inIterBegin,inIterEnd)
into the destination range, starting at outIterEnd.
Return value:
An iterator pointing at the position after the last moved element (the
first one not overwritten).
Complexity:
Linear in the size of the source range.
Notes:
Copies elements if the type of the element does not support move
semantics. The destination range must be large enough to receive the
moved elements, or insert iterators must be used.
- move_backward1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to ...
template<class InIterator,
class OutIterator>
OutIterator move_backward(InIterator inputBegin,
InIterator inputEnd,
OutIterator outputEnd);
- none_of(inIterBegin, inIterEnd, unPred)
-
Action:
Determines whether no element in the range
[inIterBegin,inIterEnd) satisfies the unary predicate
unPred.
Return value:
true if no value satisfies the predicate, false
otherwise.
Complexity:
Linear in the size of the input range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- none_of1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to determine whether a vector of integers contains
no odd integers.
template<class InIterator,
class UnaryPred>
bool none_of(InIterator inputBegin,
InIterator inputEnd,
UnaryPred matchTestPred);
- partition_copy(inIterBegin, inIterEnd, outIterTrue, outIterFalse, unPred)
-
Action:
Copies elements from the range [inIterBegin,inIterEnd).
Those elements that satisfy unPred are copied to the range
starting at outIterTrue, while those elements that do not
satisfy unPred are copied to the range starting at
outIterFalse.
Return value:
A pair of iterators in which the first component points to the end
of the range of elements copied to outIterTrue and the
second component points to the end of the range of elements copied
to outIterFalse.
Complexity:
Linear in the size of the range.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range. The
output ranges must be large enough to accommodate the copied elements.
- partition_point1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to copy odd integers to one destination and
even integers to another.
template<class InIterator,
class OutIterator1,
class OutIterator2
class UnaryPred>
ForIterator partition_copy(InIterator inputBegin,
InIterator inputEnd,
OutIterator1 outIterTrue,
OutIterator2 outIterFalse,
UnaryPred unPred);
- partition_point(forIterBegin, forIterEnd, unPred)
-
Action:
Typical usage would have the elements in the range
[inIterBegin,inIterEnd) partitioned in the sense that
all elements that satisfy the unary predicate unPred come
before those that do not, and this algorithm then returns an iterator
pointing to the first element past the subrange for which
unPred succeeds, or to forIterEnd if
unPred succeeds for all elements.
Return value:
An iterator as described above.
Complexity:
Logarithmic for random access iterators, and otherwise linear.
Notes:
unPred must take a single parameter that has the same
type as the component type of the values in the given range.
- partition_point1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to find the first even integer when a range
of integers in a vector is partitioned into odds and evens. Note
what happens when the integers are not in fact partitioned.
template<class ForIterator,
class UnaryPred>
ForIterator partition_point(ForIterator inputBegin,
ForIterator inputEnd,
UnaryPred matchTestPred);
- shuffle(randIterBegin, randIterEnd, uniformRNG)
-
Action:
Shuffles the order of the elements in the range
[inIterBegin,inIterEnd) using the uniform random number
generator uniformRNG from the random numbers and distributions
library in <random>.
Return value: void
Complexity:
Linear in the size of the range.
Notes:
Do not pass a temporarily created engine. Instead, give the engine a
name, and then pass the name.
- shuffle1a.cpp |
Windows_executable |
program_output
(text)
- Illustrates how to shuffle the first ten positive integers,
using the default engine, using the engine reset with a seed,
and using the engine after resetting it to its default state.
template<class RandIterator,
class UnaryPred>
void shuffle(RandIterator inputBegin,
RandIterator inputEnd,
UniformRandomNumberGenerator&& engine);