The generic algorithms C ++

The standard library does not have to add a lot of functionality for each container, but to provide a set of standard algorithms, these algorithms are most independent of any particular container . These algorithms are generic (generic or called generic): they can be used for different types of containers and different types of elements.

Generic algorithms (generic algorithm) is called algorithms , because they realize the common interface some classic algorithms, such as sorting or searching; they are called generics , because they can be used for different types of elements and more container type.

 

 

Fifth, the generic algorithms structure

Algorithm requires iterative operation can be divided into five categories iterator (iterator category), each iteration for each parameter algorithm will need to provide its specified what kind of iterators.

  • Input iterator (input iterators): read-only, do not write, single-pass scanning, only increment;
  • Iterator the Output (output iterator): just write, do not read, single-pass scanning, only increment;
  • Iterator Forward (Forward iterators): can read and write, many times scanning, only increment;
  • Iterator Bidirectional (Bidirectional iterators): can read and write, many times for scanning, gradual increase and decrease;
  • Access Iterator the Random (random access iterators): can read and write, multi-pass scan, support all iterators operation;

 

Guess you like

Origin www.cnblogs.com/ccpang/p/11303839.html