Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

Algorithms



Summary

Generic algorithms for performing various operations on containers and sequences.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>

The synopsis of each algorithm appears in its entry in the reference guide.

Description

The Standard C++ Library allows you to apply generic algorithms to containers, and it supplies a set of these algorithms for searching, sorting, merging, transforming, scanning, and more.

Each algorithm can be applied to a variety of containers, including those defined by a user of the library. The following design features make algorithms generic:

In addition to requiring certain iterator capabilities, algorithms may require a container to be in a specific state. For example, some algorithms can only work on previously sorted containers.

Because most algorithms rely on iterators to gain access to data, they can be grouped according to the type of iterator they require, as is done in the Algorithms by Iterator section below. They can also be grouped according to the type of operation they perform.

Algorithms by Mutating/Non-mutating Function

The broadest categorization groups algorithms into two main types: mutating and non-mutating. Algorithms that alter (or mutate) the contents of a container fall into the mutating group. All others are considered non-mutating. For example, both fill and sort are mutating algorithms, while find and for_each are non-mutating.

Non-mutating operations

Mutating operations

Note that the library has place and copy versions of many algorithms, such as replace and replace_copy. The library also has versions of algorithms that allow the use of default comparators and comparators supplied by the user. Often these functions are overloaded, but in some cases (where overloading proved impractical or impossible) the names differ (for example, replace, which uses equality to determine replacement, and replace_if, which accesses a user-provided compare function).

Algorithms by Operation

We can further distinguish algorithms by the kind of operations they perform. The following lists all algorithms by loosely grouping them into similar operations.

Initializing operations

Search operations

Binary search operations (Elements must be sorted)

Compare operations

Copy operations

Transforming operations

Swap operations

Scanning operations

Remove operations

Sorting operations

Merge operations (Elements must be sorted)

Set operations (Elements must be sorted)

Heap operations

Minimum and maximum

Permutation generators

Algorithms by Category

Each algorithm requires certain kinds of iterators (for a description of the iterators and their capabilities see the Iterator entry in this manual). The following set of lists groups the algorithms according to the types of iterators they require.

Algorithms that use no iterators:

Algorithms that require only input iterators:

Algorithms that require only output iterators:

Algorithms that read from input iterators and write to output iterators:

Algorithms that require forward iterators:

Algorithms that read from forward iterators and write to output iterators:

Algorithms that require bidirectional iterators

Algorithms that read from bidirectional iterators and write to output iterators:

Algorithms that require random access iterators:

Algorithms that read from input iterators and write to random access iterators:

Complexity

The complexity for each of these algorithms is given in the manual page for that algorithm.

See Also

Manual pages for each of the algorithms named in the lists above.



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998