C ++ STL (4): algorithm introduction, 7 types of algorithm Classification

Source: Internet
Author: User

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

Related Article

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.