C ++ algorithm (STL)

Source: Internet
Author: User

Display All entries for C ++ algorithms on one page, or view entries individually:

Accumulate
Sum up a range of elements
Sum: add an initial value to an element in the specified range. The overloaded version is no longer used for addition, but the binary operators passed in are applied to elements.

Adjacent_difference
Compute the differences between adjacent elements in a range
Create a new sequence. Each new value of the sequence represents the difference between the current element and the previous element. The overloaded version uses the specified binary operation to calculate the difference between adjacent elements.

Adjacent_find
Finds two items that are adjacent to eachother
Searches for a pair of adjacent duplicate elements within the specified range. If a forwarditerator is found, it points to the first element of the pair. Otherwise, return last. The overloaded version uses the input binary operator instead of the equal judgment.

Binary_search
Determine if an element exists in a certain range
Binary/Binary Search: searches for values in an ordered sequence. If yes, true is returned. The overloaded version uses the specified comparison function object or function pointer to determine the equality.

Copy
Copy some range of elements to a new location
Copy Sequence.

Copy_backward
Copy a range of elements in backwards order
Except that the elements are copied in the reverse order, the other elements are the same as the copy element.

Copy_n
Copy n elements
Copy only n elements.

Count
Return the number of elements matching a given value
Use the equal operator to compare the elements of the Flag range class with the input value and return the number of equal elements.

Count_if
Return the number of elements for which a predicate is true
Apply the input operator to elements in the flag range class and return the number of times the result is true.

Equal
Determine if two sets of elements are the same
If the two sequences have the same element in the range, equal returns true. The overloaded version uses the input operator instead of the default equal operator.

Performance_range
Search for a range of elements that are all equal to a certain element
Returns an iterator. The first iterator represents the iterator returned by lower_bound, and the second iterator value returned by upper_bound.

Fill
Assign a range of elements a certain value
Fill: copy the input value to each element in the range.

Fill_n
Assign a value to some number of elements
Fill: Assign the input value to elements in the first to frist + N range.

Find
Find a value in a given range
Search: Use the equals operator of the underlying element to compare the elements in the range with the input values. When the match ends, an inputiterator of the element is returned.

Find_end
Find the last sequence of elements in a certain range
Search: the input function replaces the equal operator to execute find.

Find_first_of
Search for any one of a set of elements
Search: In the range, find the last occurrence of "second sequence of the sign of another input iterator. The overload version uses the operator entered by the user to replace the equals operation.

Find_if
Find the first element for which a certain predicate is true
Search: searches for the first appearance of any element in the second sequence of the sign of another iterator input within the range. The overload version uses User-Defined operators.

For_each
Apply a function to a range of elements
Execute input functions for all elements in the range in sequence.

Generate
Saves the result of a function in a range
Fill in the specified range by calling the input function Gen consecutively.

Generate_n
Saves the result of N applications of a function
Fill n elements.

Includes
Returns true if one set is a subset of another
Determine whether an element of [first1, last1) is included in another sequence. The <= operator of the underlying element is used, and the overloaded version uses the user-input function.

Inner_product
Compute the inner product of two ranges of Elements
Perform inner product on the two sequences (the corresponding elements are multiplied and then summed), and add inner product to the initial value of an input. The overloaded version uses user-defined operations.

Inplace_merge
Merge two ordered ranges in-place
Merge two consecutive chronological sequences. The result sequence covers the range of both ends. The overloaded version uses the input operation for sorting.

Is_heap
Returns true if a given range is a heap
Determines whether the specified range is a heap.

Is_sorted
Returns true if a range is sorted in ascending order
Determines the specified range in ascending order.

Iter_swap
Swaps the elements pointed to by two iterators
Exchange the values of two forwarditerator.

Lexicographical_compare
Returns true if one range is lexicographically less than another
Compare two sequences (using less ). The reload version uses custom comparison operations.

Lexicographical_compare_3way
Determines if one range is lexicographically less than or greater than another
Determine the element of the first range, which is smaller than or greater than the other range.
Similar to the memcmp return rules.

Lower_bound
Search for the first place that a value can be inserted while preserving order
Returns an iterator pointing to the first position in the ordered sequence within the range where a specified value can be inserted without disrupting the container sequence. The overload function uses custom comparison operations.

Make_heap
Creates a heap out of a range of elements
Generate a heap for the elements in the range. Reload versions use custom comparison operations.

Max
Returns the larger of two elements
Returns the larger one of the two elements. The overloaded version uses a custom comparison operation.

Max_element
Returns the largest element in a range
Returns an iterator that specifies the largest element in the sequence. Reload versions use custom comparison operations.

Merge
Merge two sorted ranges
Merge two ordered sequences and place them in another sequence. Reload versions use custom comparisons.

Min
Returns the smaller of two elements
Similar to Max, but returns the smallest element.

Min_element
Returns the smallest element in a range
Similar to max_element, but returns the smallest element.

Mismatch
Finds the first position where two ranges differ
Compares two sequences in parallel, indicating the first unmatched position. It returns a pair of iterator, marking the first unmatched element position. If all matches, the last of each container is returned. Reload versions use custom comparison operations.

Next_permutation
Generates the next greater lexicographic permutation of a range of elements
Sort the data in the current range and sort the data into the next one. Reload versions use custom comparison operations.

Nth_element
Put one element in its sorted location and make sure that no elements to its left are greater than any elements to its right
Sorts the sequences in the range so that all elements smaller than the nth element appear before it, and those greater than it appear behind it, the overloaded version uses custom comparison operations.

Partial_sort
Sort the first n elements of a range
Partially sorts the entire sequence, and the number of elements to be sorted can be placed in the range. Reload versions use custom comparison operations.

Partial_sort_copy
Copy and partially sort a range of elements
Similar to partial_sort, apart from copying the sorted sequence to another container.

Partial_sum
Compute the Partial Sum of a range of elements
Create a new element sequence. The value of each element represents the sum of all elements before the position in the range. The overloaded version uses custom operations instead of addition.

Partition
Divide a range of elements into two groups
Sorts the elements in the specified range. The input function is used to place all elements whose calculation result is true before the elements whose results are false.

Pop_heap
Remove the largest element from a heap
Instead of popping up the largest element from the heap, you can sort the heap again. It exchanges first and last-1, and then creates a new heap. You can use the back of the container to access the "pop-up" element or use pop_back to delete it. Reload versions use custom comparison operations.

Prev_permutation
Generates the next smaller lexicographic permutation of a range of elements
Extract the sequence in the range and reorder it into the previous sequence. If the previous sequence does not exist, false is returned. Reload versions use custom comparison operations.

Push_heap
Add an element to a heap
Assume that the first to last-1 is a valid heap. The element to be added to the heap is in the last-1 position and the heap is regenerated. Before pointing to this function, you must insert the element into the container. The reload version uses the specified comparison.

Random_sample
Randomly copy elements from one range to another

Random_sample_n
Sample n random elements from a range

Random_shuffle
Randomly re-order elements in some Range
Randomly adjust the order of elements in the range. Input a random number to generate a random number for the overloaded version.

Remove
Remove elements equal to certain value
Delete all the elements within the specified range. Note that this function does not actually Delete the elements. Built-in arrays are not suitable for removing and remove_if functions.

Remove_copy
Copy a range of elements omitting those that match a certian Value
Copy all mismatched elements to a specified container, and the returned outputiterator points to the next position of the last copied element.

Remove_copy_if
Create a copy of a range of elements, omitting any for which a predicate is true
Copy all unmatched elements to a specified container.

Remove_if
Remove all elements for which a predicate is true
Delete all elements whose input operation results are true.

Replace
Replace every occurrence of some value in a range with another value
Replace all the elements in the range equal to old_value with new_value.

Replace_copy
Copy a range, replacing certain elements with new ones
Similar to replace, but writes the result to another container.

Replace_copy_if
Copy a range of elements, replacing those for which a predicate is true
Similar to replace_if, but write the result to another container

Replace_if
Change the values of elements for which a predicate is true
Replace all the elements whose operation result is true with the new value.

Reverse
Reverse elements in some Range
Sort the elements in the range in reverse order.

Reverse_copy
Create a copy of a range that is reversed
Similar to reverse, but write the results to another container.

Rotate
Move the elements in some range to the left by some amount
Move the element in the range to the end of the container, and the element pointed to by middle becomes the first element of the container.

Rotate_copy
Copy and rotate a range of elements
Similar to rotate, but write the result to another container

Search
Search for a range of elements
Two ranges are provided, and an iterator is returned, pointing to the position where the subsequence appears for the first time in the range. Reload versions use custom comparison operations.

Search_n
Search for N consecutive copies of an element in some Range
Search for subsequences whose values appear n times in a range. Reload versions use custom comparison operations.

Set_difference
Computes the difference between two sets
Construct an ascending sequence. The elements appear in the first sequence but are not included in the second sequence. Reload versions use custom comparison operations.

Set_intersection
Computes the intersection of two sets
Construct an ascending sequence. The elements exist in both sequences. Reload versions use custom comparison operations.

Set_effecric_difference
Computes the specified Ric difference between two sets
Construct an ascending sequence. The elements appear in the first sequence, but do not appear in the second sequence. Reload versions use custom comparison operations.

Set_union
Computes the union of two sets
Construct an out-of-order sequence that contains all non-repeating elements in the two sequences. Reload versions use custom comparison operations.

Sort
Sort a range into ascending order
Elements in the range are rearranged in ascending order, and the overloaded version uses custom comparison operations.

Sort_heap
Turns a heap into a sorted range of elements
Sorts a sequence in a range. It is assumed that the sequence is an ordered heap. Reload versions use custom comparison operations.

Stable_partition
Divide elements into two groups while preserving their relative order
Similar to partition, But it ensures that the relative sequence in the container is retained.

Stable_sort
Sort a range of elements while preserving order between equal elements
Similar to sort, but the sequential relationship between equal elements is retained.

Swap
Swap the values of two objects
Exchange Values stored in two objects.

Swap_ranges
SWAps two ranges of Elements
The elements in the range are exchanged with the element values of another sequence.

Transform
Applies a function to a range of elements
Apply the input operation to each element in the range and generate a new sequence. The overloaded version applies the operation to one element, and the other element comes from another input sequence. The result is output to the specified container.

Unique
Remove consecutive duplicate elements in a range
Clear repeated elements in the sequence. Similar to removing, it cannot actually Delete elements. The overloaded version uses custom operations.

Unique_copy
Create a copy of some range of elements that contains no consecutive duplicates
Similar to unique, but It outputs the result to another container.

Upper_bound
Searches for the last possible location to insert an element into an ordered Range
Returns an iterator pointing to the last position where values are inserted in the ordered sequence within the range without disrupting the container order. This position indicates a value greater than the value. The overloaded version uses the input comparison operation.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/cclsoft/archive/2009/08/03/4403509.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.