STL Algorithm Overview __ Algorithm

Source: Internet
Author: User

#include <algorithm>//c++ standard library algorithm

#include <functional>//imitation functions and function connectors

1.nonmodifying algorithm algorithm (no change of elements, that is, only read)

The algorithm of 2.modifying algorithm variability

The algorithm of 3.removing algorithm removal

The algorithm of 4.mutating algorithm variable order

5.sorting algorithm sorting algorithm

6,sorted range algorithm sequential interval algorithm

7.numeric algorithm numerical algorithm

Difference_type used for measuring distances, distinguishing between positive and negative

1. Non-variable algorithm

(1) For_each (begin,end,unary_func op) specifically see the other blog

(2) Difference_type count (Begin,end,const t&value); Returns the number of value

(3) Difference_type count_if (begin,end,unarypredicate op); Returns the number of elements in which the OP is true

(4) Iterator min_element (begin,end); Default less than

Iterator Min_element (Begin,end,compfunc op); OP (elem1,elem2);

(5) Iterator max_element (begin,end);

Iterator Max_element (Begin,end,compfunc op);

(6) Iterator find (Begin,end,const t&value);

(7) Iterator find_if (begin,end,unarypredicate op);

If the sequence interval is Lower_bound (), Upper_bound (), Equal_range (), Binary_search () can obtain higher performance

(8) Input_iterator search_n (begin,end,size count,const t& value); Successive count element values are all value

Input_iterator search_n (begin,end,size count,const t&value,Binary op);

Consecutive count elements cause op to be true, OP (elem,value)

(9) Fowarditerator search (BEGIN1,END1,BEGIN2,END2); Look for elements in [begin1,end1) that are the same as [Begin2,end2]

Fowarditerator Search (Begin1,end1,searchbegin2,searchend2,Binarypredicate op);

OP (Elem,searchelem),

(a) Forward_iterator find_end (BEGIN1,END1,SEARCHBEGIN2,SEARCHEND2);

[Begin1,end1] (last appearing in [Searchbegin2,searchend2)

Forward_iterator find_end (begin1,end1,searchbegin2,searchend2,binarypredicate op);

OP (Elem,searchelem);

(11) Find_first_of Lookup has nothing to do with order.

Forward_iterator find_first_of (Begin1,end1,searchbegin2,searchend2)

Returns an element position that occurs both in the interval [begin1,end1) and in [Searchbegin2,searchend2]

Forward_iterator find_first_of (begin1,end1,searchbegin2,searchend2,binarypredicate op);

Returns the OP (Elem,searchelem) to True in an interval [begin1,end1) and interval [Searchbegin2,searchend2]

(a) Inputiterator adjacant_find (begin,end); Returns the first position of a contiguous two equal elements

Inputiterator adjacant_find (begin,end,binarypredicate op);

OP (Elem,nextelem), two consecutive elements so that the following two-dollar judgment result is true

(a) bool equal (BEGIN1,END1,BEGIN2);

BOOL Equal (Begin1,end1,begin2,binarypredicate op); OP (Elem,cmpelem);

(a) pair<inputiterator1,inputiterator2> mismatch (InputIterator1 begin,inputiterator1 End,inputiterator2 Cmpbeg)

Returns the first set of distinct corresponding elements of the interval at the beginning of [begin,end) and Cmpbeg

       pair<InputIterator1,InputIterator2> mismatch (InputIterator1 Begin,inputiterator1 End,inputiterator2 Cmpbeg,

Binarypredicate op);

OP (Elem,cmpelem); Returns the corresponding element that makes the judgment false

(a) bool Lexicographical_compare (BEGIN1,END1,BEGIN2,END2);

BOOL Lexicographical_compare (Begin1,end1,begin2,end2,comfunc op);

OP (elem1,elem2); Elem1 is less than elem2 is true

Dictionary order Definition:

1. True if the number of the first sequence is small

2. False for Equality

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.