Algorithm in the STL

Source: Internet
Author: User

Algorithm in the STL

#include the functional algorithm in <algorithm>, you need to add a header file.

Search algorithm: Find (), search (), count (), find_if (), search_if (), count_if ()
Sort by Category: sort (), merge ()
Delete algorithm: Unique (), remove ()
Generation and mutation: Generate (), fill (), Transformation (), copy ()
Relational algorithms: Equal (), Min (), Max ()

eg

Sort (V1.begin (), Vi.begin () +v1.size/2), sorting the first half of the V1 element list<char>::iterator pmiddle = Find (Clist.begin (), Clist.end (),'A'); Returns the pointer to the first occurrence of the checked content, otherwise returns end (). Vector< typeName >::size_type x; vector< typeName > Type count, can be used for loops like for (int i)


The following procedure is incorrect

vector<int> Ivec;   Empty vectorfor (Vector<int>::size_type ix = 0; IX = ten; ++ix)     Ivec[ix] = IX; // Disaster:ivec has no elements

The above program attempts to insert 10 new elements into the Ivec, with the element values sequentially from 0 to 9 integers. However, here Ivec is an empty vector object, and the subscript can only be used to get an existing element.

Use the following notation to write data in a container:

 for (vector<int0; + +ix)      // Ok:adds new element with value IX

Warning: Must be an existing element to be indexed with the subscript operator. When you assign a value by using the subscript operation, no element is added. Subscript operation is only possible for elements that are known to exist

Algorithm in the STL

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.