adjacent_find, merge, and inplace_merge

The adjacent_find function is used to find the first occurrence of consecutive elements that meet a certain criteria. The first version of the function uses a criteria of equality, while the second version of the function uses a boolean function that takes two arguments (the arguments will be the current element and the one immediately following it). Both of the functions will return an iterator to first of the consecutive elements, otherwise an iterator to the "end" of the range will be returned.

iterator adjacent_find( start_iterator, end_iterator );

iterator adjacent_find( start_iterator, end_iterator, boolean_function_two_arguments );

The merge function merges two sorted lists and results in a sorted list. The two lists to be merged must be sorted using the same sort criteria. The first version of the function uses less than as the ordering criteria, while the second version allows the ordering criteria to be specified as a boolean function that takes two arguments (the arguments will be compared in the manner "element in range 1" operator "element in range 2"). Both versions will return an iterator that references the "end" of the destination list.

The two source ranges are not modified and the destination range should not overlap with the source ranges.

iterator merge( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator );

iterator merge( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator, boolean_function_takes_two_args );

The inplace_merge function combines two sorted consecutive sequences.

void inplace_merge( start_iterator, middle_iterator, end_iterator );

void inplace_merge( start_iterator, middle_iterator, end_iterator, boolean_function_takes_two_args );

For both versions, the sequences that will be merged are: start_iterator...middle_iterator - 1 AND middle_iterator...end_iterator - 1.

The merged sequence will overwrite the original values starting at start_iterator.

The first version of the function uses less than as the ordering criteria, while the second version allows the ordering criteria to be specified as a boolean function that takes two arguments (the arguments will be compared in the manner "element in sequence 1" operator "element in sequence 2").


reverse, reverse_copy, rotate, and rotate_copy

The reverse algorithm reverses the order of the elements in a given range.

void reverse( start_iterator, end_iterator );

The reverse_copy algorithm reverses the elements in a given range and copies the result into a specified destination. The original source is not modified. An iterator to the "end" of the destination range will be returned.

iterator reverse_copy( start_iterator, end_iterator, destination_iterator );

The rotate algorithm rotates the elements in a given range.

void rotate( start_iterator, newStart_iterator, end_iterator );

The elements in the range start_iterator...newStart_iterator - 1 will be rotated with the elements in the range newStart_iterator...end_iterator - 1.

The rotate_copy algorithm rotates the elements in a given range and copies the result into a specified destination in rotated order. The original source is not modified.

iterator rotate_copy( start_iterator, newStart_iterator, end_iterator, destination_iterator );

The elements in the range start_iterator...newStart_iterator - 1 will be rotated with the elements in the range newStart_iterator...end_iterator - 1 and will be positioned starting at destination_iterator.


count, count_if, max, max_element, min, min_element, and random_shuffle

The count algorithm counts the occurrences of a given value within a given range.

int count( start_iterator, end_iterator, value_to_be_counted );

The count_if algorithm counts the occurrences of a given value within a given range that meet a specified criteria. The criteria is specified by a boolean function that takes one argument.

int count_if( start_iterator, end_iterator, value_to_be_counted, boolean_function_take_one_argument );

The max algorithm determines the maximum of two values, while the max_element algorithm determines the maximum value within a specified range.

data_type_of_elements max( element1, element2 );

data_type_of_elements max_element( start_iterator, end_iterator );

The min algorithm determines the minimum of two values, while the min_element algorithm determines the minimum value within a specified range.

data_type_of_elements min( element1, element2 );

data_type_of_elements min_element( start_iterator, end_iterator );

The random_shuffle algorithm randomly orders the elements within a given range. The first version of the function reorders the elements using a uniform distribution random number generator, while the second version uses a specified random number generating function object or pointer to a function.

void random_shuffle( start_iterator, end_iterator );

void random_shuffle( start_iterator, end_iterator, random_number_generator );


for_each and transform

The for_each algorithm will access and process each element within a given range. The process that is performed is specified by function.

for_each( start_iterator, end_iterator, function );

The transform algorithm will create a sequence of values by applying a function to the values within a specified range. The function that is applied takes one argument and returns a value of the appropriate type. The transform algorithm will return an iterator to the "end" of the destination values.

iterator transform( start_iterator, end_iterator, destination_iterator, function_take_one_argument );

The other version of the transform algorithm will create a sequence by applying a function to corresponding values from within two specified ranges. The function that is applied takes two arguments and returns a value of the appropriate type. The transform algorithm will return an iterator to the "end" of the destination values.

iterator transform( start_iterator1, end_iterator, start_iterator2, destination_iterator, function_takes_two_arguments );


includes, set_intersection, set_union, set_difference, and set_symmetric_difference

These are all set theory algorithms.

The includes algorithm determines whether the elements in one range appear in another range. The elements within the two ranges are assumed to be sorted using the same sort criteria. The first version of the algorithm assumes that the elements are sorted in ascending order. The second version allows for the sort criteria to be specified

bool includes( start_iterator1, end_iterator1, start_iterator2, end_iterator2 );

bool includes( start_iterator1, end_iterator1, start_iterator2, end_iterator2, function_takes_two_arguments );

The set_intersection algorithm finds the elements that are common to two ranges of elements. The elements within each range must be sorted. The common elements will be copied to another container and will be in sorted order. The first version of the algorithm assumes that the elements within each range are in ascending order. The second version allows the sort criteria to be specified. The elements within the starting ranges are not modified.

iterator set_intersection( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator );

iterator set_intersection( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator, sort_type );

The set_union algorithm finds the elements that are contained within two specified ranges. The elements within each range must be sorted. The resulting elements will be copied to another container and will be in sorted order. The first version of the algorithm assumes that the elements within each range are in ascending order. The second version allows the sort criteria to be specified. The elements within the starting ranges are not modified.

iterator set_union( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator );

iterator set_union( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator, sort_type );

The set_difference algorithm finds the elements in one range of elements that do not appear in the elements of another range. The elements within each range must be sorted. The resulting elements will be copied to another container and will be in sorted order. The first version of the algorithm assumes that the elements within each range are in ascending order. The second version allows the sort criteria to be specified. The elements within the starting ranges are not modified.

iterator set_difference( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator );

iterator set_difference( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator, sort_type );

The set_symmetric_difference algorithm finds the elements in one range of elements that do not appear in the elements of a second range AND the elements of the second range that are not in the first range. The elements within each range must be sorted. The resulting elements will be copied to another container and will be in sorted order. The first version of the algorithm assumes that the elements within each range are in ascending order. The second version allows the sort criteria to be specified. The elements within the starting ranges are not modified.

iterator set_symmetric_difference( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator );

iterator set_symmetric_difference( start_iterator1, end_iterator1, start_iterator2, end_iterator2, destination_iterator, sort_type );


accumulate, adjacent_difference, inner_product, and partial_sum

These are all numeric function and therefore will manipulate numeric data. Each of the algorithms has two versions. The first version uses the natural operation to manipulate the data (ie. accumulate will use addition to find a sum). The second version allows the operation to manipulate the data to be specified (ie. accumulate could use multiplication).

The accumulate algorithm will add all of the elements within a specified range to an initial value. The resulting sum is returned.

element_data_type accumulate( start_iterator, end_iterator, initial_value );

element_data_type accumulate( start_iterator, end_iterator, initial_value, binary_operator_function );

The adjacent_difference will create a sequence of elements where each value is equal to the difference of the current value and previous value from within a specified sequence of elements. The first value of the created sequence is always equal to the first value from the specified sequence.

iterator adjacent_difference( start_iterator, end_iterator, destination_iterator );

iterator adjacent_difference( start_iterator, end_iterator, destination_iterator, binary_operator_function );

The inner_product algorithm will add all of the products that result from multiplying the corresponding values from within two specified ranges to an initial value. The second version allows the default operations of addition and multiplication to be specified.

element_data_type inner_product( start_iterator1, end_iterator, start_iterator2, initial_value );

element_data_type inner_product( start_iter1, end_iter, start_iter2, init_value, binary_oper_func1, binary_oper_func2 );

The partial_sum algorithm will create a sequence of elements where each value is equal to the sum of all of the previous elements. The first value of the created sequence is always equal to the first value from the specified sequence. The algorithm will return an iterator that refers to the "end" of the created sequence.

iterator partial_sum( start_iterator, end_iterator, destination_iterator );

iterator partial_sum( start_iterator, end_iterator, destination_iterator, binary_operator_function );