Part10 generic Programming and C + + Standard Template Library 10.7 algorithm

Source: Internet
Author: User

The STL algorithm itself is a function template
Getting input data through iterators
Working with data through function objects
Output a result from an iterator
STL algorithms are generic, independent of specific data types, container types

STL Algorithm Classification
Non-variable sequence algorithm
Variable sequence algorithm
Sorting and searching algorithms
Numerical algorithms

Non-variable sequence algorithm
Algorithms that do not directly modify the contents of the container being manipulated
Used to find the specified element, compare two sequences for equality, count elements, etc.
Cases:
Template<class Inputiterator, Class unarypredicate>
Inputiterator find_if (inputiterator First, Inputiterator last, Unarypredicate pred);
Find the first element that pred (x) is true in the [initial, last] interval

Variable sequence algorithm
You can modify the container objects that they manipulate
Algorithms that include copying, deleting, replacing, descending, rotating, swapping, splitting, removing, filling, shuffling, and generating a sequence of sequences
Cases:
Template<class ForwardIterator, Class t>
Inputiterator find_if (forwarditerator first, ForwardIterator last, const t& x);
The elements in the [first, last] interval are all rewritten to X.

Sorting and searching algorithms
To sort a sequence
Merging two ordered sequences
Searching for ordered sequences
Set operations for ordered sequences
Heap algorithm
Cases:
Template <class Randomaccessiterator, class unarypredicate>
void sort (randomaccessiterator first, Randomaccessiterator last, Unarypredicate comp);
Sort the data in the [first, last] interval with the function object comp as "<"

Numerical algorithms
Finding the "and", the "and", the "difference" of the adjacent elements or the inner product of two sequences in the sequence
"+", "Difference" "-" and "+" and "•" of the inner product. Can be specified by a function object
Cases:
Template<class Inputiterator, Class Outputiterator, class binaryfunction>
Outputiterator Partial_sum (inputiterator First, inputiterator last, outputiterator result, binaryfunction op);
For the elements within [first, last], the "and" (so-called parts and ", is a sequence of the same length as the input sequence, whose nth entry is the" and "of the first n elements of the input sequence), with the Function object op as the" + "operator, and the result is output by result, The returned iterator points to the next element of the last element of the output sequence

Part10 generic Programming and C + + Standard Template Library 10.7 algorithm

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.