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