I. Algorithms
The algorithm is implemented in the form of a function template. Common algorithms include comparison, exchange, search, search, replication, modification, removal, reversal, sorting, and merge.
The algorithm is not a member function of the container type, but a global function. It must be used together with the iterator.
The advantage of the algorithm is that you only need to implement one copy to adapt to all containers without having to customize the quantity of each container. It can also be used with custom containers.
Algorithm tail word:
_ If
For example, find (search by a value) and find_if (search by a condition)
_ Copy
This ending word is used to indicate that in an algorithm, elements are not only operated, but also copied to the target range. For example, reverse and reverse_copy
Ii. algorithm Classification
1. Non-variability algorithms neither change the element order nor change the element value.
2. The variable algorithm either directly changes the element value or changes the element value while copying it to another interval. In the second case, the original interval will not change.
3. The removal algorithm is a special variability algorithm. Removing algorithms remove certain elements within a range. These algorithms do not change the number of elements. They are only logical thinking, move the "do not need to remove elements" that are originally placed behind it to overwrite those removed elements. They all return the logical endpoints between new zones. The removal algorithm can also be removed during the copy process. Note that the target range cannot be an associated container.
4. The variable order algorithm changes the element order, but does not change the element value. These algorithms cannot be used for Associative containers because elements in an associative container have a fixed order.
5. the sorting algorithm is a special variable-order algorithm. But it is more complicated than general variable-order algorithms, and takes more time.
6. Ordered interval algorithms. Generally, the results of these algorithms are still sequential.
7. Add the header file # include <numeric> to the numeric algorithm.
In the subsequent articles, we will give examples of the seven algorithms.
Refer:
C ++ primer version 4
Valid tive C ++ 3rd
C ++ programming specifications