C++-Referenz/ Standardbibliothek/ Algorithmen

Symbol opinion vote.svg
Alte Seite

Die Arbeit am Buch »C++-Referenz« wurde vom Hauptautor eingestellt. Ein Lehrbuch zum Thema C++ ist unter »C++-Programmierung« zu finden. Eine sehr umfangreiche und gute Referenz gibt es unter cppreference.com.

Diese Seite beschreibt C++98, einen stark veralteten Standard. Aktuelle Referenz.

Nicht-Modifizierende sequenzoperationenBearbeiten

for_eachBearbeiten

// Header: algorithm
template<typename InputIterator, typename Function>
Function for_each(InputIterator first, InputIterator last, Function f);

findBearbeiten

// Header: algorithm
template<typename InputIterator, typename T>
InputIterator find(InputIterator first, InputIterator last, const T& value);

find_ifBearbeiten

// Header: algorithm
template<typename InputIterator, typename Predicate>
InputIterator find_if(InputIterator first, InputIterator last, Predicate pred);

find_endBearbeiten

// Header: algorithm
template<typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator1 find_end(
    ForwardIterator1 first1, ForwardIterator1 last1,
    ForwardIterator2 first2, ForwardIterator2 last2
);

template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
ForwardIterator1 find_end(
    ForwardIterator1 first1, ForwardIterator1 last1,
    ForwardIterator2 first2, ForwardIterator2 last2,
    BinaryPredicate pred
);

find_first_ofBearbeiten

// Header: algorithm
template<typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator1 find_first_of(
    ForwardIterator1 first1, ForwardIterator1 last1,
    ForwardIterator2 first2, ForwardIterator2 last2
);

template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
ForwardIterator1 find_first_of(
    ForwardIterator1 first1, ForwardIterator1 last1,
    ForwardIterator2 first2, ForwardIterator2 last2,
    BinaryPredicate pred
);

adjacent_findBearbeiten

// Header: algorithm
template<typename ForwardIterator>
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last);

template<typename ForwardIterator, typename BinaryPredicate>
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);

countBearbeiten

// Header: algorithm
template<typename InputIterator, typename T>
iterator_traits<InputIterator>::difference_type count(
    InputIterator first, InputIterator last, const T& value
);

count_ifBearbeiten

// Header: algorithm
template<typename InputIterator, typename Predicate>
iterator_traits<InputIterator>::difference_type count_if(
    InputIterator first, InputIterator last, Predicate pred
);

mismatchBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2>
pair<InputIterator1, InputIterator2> mismatch(
    InputIterator1 first1, InputIterator1 last1, InputIterator2 first2
);

template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
pair<InputIterator1, InputIterator2> mismatch(
    InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred
);

equalBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2>
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);

template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred);

searchBearbeiten

// Header: algorithm
template<typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator1 search(
    ForwardIterator1 first1, ForwardIterator1 last1,
    ForwardIterator2 first2, ForwardIterator2 last2
);

template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
ForwardIterator1 search(
    ForwardIterator1 first1, ForwardIterator1 last1,
    ForwardIterator2 first2, ForwardIterator2 last2,
    BinaryPredicate pred
);

search_nBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename Size, typename T>
ForwardIterator search_n(
    ForwardIterator first, ForwardIterator last, Size count, const T& value
);

template<typename ForwardIterator, typename Size, typename T, typename BinaryPredicate>
ForwardIterator search_n(
    ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred
);

Modifizierende sequenzoperationenBearbeiten

KopierenBearbeiten

copyBearbeiten

// Header: algorithm
template<typename InputIterator, typename OutputIterator>
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result);

copy_backwardBearbeiten

// Header: algorithm
template<typename BidirectionalIterator1, typename BidirectionalIterator2>
BidirectionalIterator2 copy_backward(
    BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result
);

VertauschenBearbeiten

swapBearbeiten

// Header: algorithm
template<typename T>
void swap(T& a, T& b);

swap_rangesBearbeiten

// Header: algorithm
template<typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator2 swap_ranges(
    ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2
);

iter_swapBearbeiten

// Header: algorithm
template<typename ForwardIterator1, typename ForwardIterator2>
void iter_swap(ForwardIterator1 a, ForwardIterator2 b);

transformBearbeiten

// Header: algorithm
template<typename InputIterator, typename OutputIterator, typename UnaryOperation>
OutputIterator transform(
    InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op
);

transformBearbeiten

// Header: algorithm
template<
    typename InputIterator1, typename InputIterator2,
    typename OutputIterator,
    typename BinaryOperation
>
OutputIterator transform(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2,
    OutputIterator result,
    BinaryOperation binary_op
);

replaceBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);

replace_ifBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename Predicate, typename T>
void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);

replace_copyBearbeiten

// Header: algorithm
template<typename InputIterator, typename OutputIterator, typename T>
OutputIterator replace_copy(
    InputIterator first, InputIterator last,
    OutputIterator result,
    const T& old_value, const T& new_value
);

replace_copy_ifBearbeiten

// Header: algorithm
template<typename Iterator, typename OutputIterator, typename Predicate, typename T>
OutputIterator replace_copy_if(
    Iterator first, Iterator last,
    OutputIterator result,
    Predicate pred,
    const T& new_value
);

fillBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
void fill(ForwardIterator first, ForwardIterator last, const T& value);

fill_nBearbeiten

// Header: algorithm
template<typename OutputIterator, typename Size, typename T>
void fill_n(OutputIterator first, Size n, const T& value);

generateBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename Generator>
void generate(ForwardIterator first, ForwardIterator last, Generator gen);

generate_nBearbeiten

// Header: algorithm
template<typename OutputIterator, typename Size, typename Generator>
void generate_n(OutputIterator first, Size n, Generator gen);

removeBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T& value);

remove_ifBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename Predicate>
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);

remove_copyBearbeiten

// Header: algorithm
template<typename InputIterator, typename OutputIterator, typename T>
OutputIterator remove_copy(
    InputIterator first, InputIterator last, OutputIterator result, const T& value
);

remove_copy_ifBearbeiten

// Header: algorithm
template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator remove_copy_if(
    InputIterator first, InputIterator last, OutputIterator result, Predicate pred
);

uniqueBearbeiten

// Header: algorithm
template<typename ForwardIterator>
ForwardIterator unique(ForwardIterator first, ForwardIterator last);

template<typename ForwardIterator, typename BinaryPredicate>
ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);

unique_copyBearbeiten

// Header: algorithm
template<typename InputIterator, typename OutputIterator>
OutputIterator unique_copy(
    InputIterator first, InputIterator last, OutputIterator result
);

template<typename InputIterator, typename OutputIterator, typename BinaryPredicate>
OutputIterator unique_copy(
    InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred
);

reverseBearbeiten

// Header: algorithm
template<typename BidirectionalIterator>
void reverse(BidirectionalIterator first, BidirectionalIterator last);

reverse_copyBearbeiten

// Header: algorithm
template<typename BidirectionalIterator, typename OutputIterator>
OutputIterator reverse_copy(
    BidirectionalIterator first, BidirectionalIterator last, OutputIterator result
);

rotateBearbeiten

// Header: algorithm
template<typename ForwardIterator>
void rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);

rotate_copyBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename OutputIterator>
OutputIterator rotate_copy(
    ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result
);

random_shuffleBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void random_shuffle(
    RandomAccessIterator first, RandomAccessIterator last
);

template<typename RandomAccessIterator, typename RandomNumberGenerator>
void random_shuffle(
    RandomAccessIterator first, RandomAccessIterator last,
    RandomNumberGenerator& rand
);

VerteilenBearbeiten

partitionBearbeiten

// Header: algorithm
template<typename BidirectionalIterator, typename Predicate>
BidirectionalIterator partition(
    BidirectionalIterator first, BidirectionalIterator last, Predicate pred
);

stable_partitionBearbeiten

// Header: algorithm
template<typename BidirectionalIterator, typename Predicate>
BidirectionalIterator stable_partition(
    BidirectionalIterator first, BidirectionalIterator last, Predicate pred
);

Sortier- und ZuordnungsoperationenBearbeiten

SortierenBearbeiten

sortBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void sort(RandomAccessIterator first, RandomAccessIterator last);

template<typename RandomAccessIterator, typename Compare>
void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);

stable_sortBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void stable_sort(RandomAccessIterator first, RandomAccessIterator last);

template<typename RandomAccessIterator, typename Compare>
void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);

partial_sortBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void partial_sort(
    RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last
);

template<typename RandomAccessIterator, typename Compare>
void partial_sort(
    RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last,
    Compare comp
);

partial_sort_copyBearbeiten

// Header: algorithm
template<typename InputIterator, typename RandomAccessIterator>
RandomAccessIterator partial_sort_copy(
    InputIterator first, InputIterator last,
    RandomAccessIterator result_first, RandomAccessIterator result_last
);

template<typename InputIterator, typename RandomAccessIterator, typename Compare>
RandomAccessIterator partial_sort_copy(
    InputIterator first, InputIterator last,
    RandomAccessIterator result_first, RandomAccessIterator result_last,
    Compare comp
);

nth_elementBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void nth_element(
    RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last
);

template<typename RandomAccessIterator, typename Compare>
void nth_element(
    RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp
);

Binäre SucheBearbeiten

lower_boundBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
ForwardIterator lower_bound(
    ForwardIterator first, ForwardIterator last, const T& value
);

template<typename ForwardIterator, typename T, typename Compare>
ForwardIterator lower_bound(
    ForwardIterator first, ForwardIterator last, const T& value, Compare comp
);

upper_boundBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
ForwardIterator upper_bound(
    ForwardIterator first, ForwardIterator last, const T& value
);

template<typename ForwardIterator, typename T, typename Compare>
ForwardIterator upper_bound(
    ForwardIterator first, ForwardIterator last, const T& value, Compare comp
);

equal_rangeBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
pair<ForwardIterator, ForwardIterator> equal_range(
    ForwardIterator first, ForwardIterator last, const T& value
);

template<typename ForwardIterator, typename T, typename Compare>
pair<ForwardIterator, ForwardIterator> equal_range(
    ForwardIterator first, ForwardIterator last, const T& value, Compare comp
);

binary_searchBearbeiten

// Header: algorithm
template<typename ForwardIterator, typename T>
bool binary_search(ForwardIterator first, ForwardIterator last, const T& value);

template<typename ForwardIterator, typename T, typename Compare>
bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);

VerbindenBearbeiten

mergeBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator merge(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result
);

template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Compare>
OutputIterator merge(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result,
    Compare comp
);

inplace_mergeBearbeiten

// Header: algorithm
template<typename BidirectionalIterator>
void inplace_merge(
    BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last
);

template<typename BidirectionalIterator, typename Compare>
void inplace_merge(
    BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last,
    Compare comp
);

SetzenBearbeiten

includesBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2>
bool includes(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2
);

template<typename InputIterator1, typename InputIterator2, typename Compare>
bool includes(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    Compare comp
);

set_unionBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator set_union(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result
);

template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Compare>
OutputIterator set_union(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result,
    Compare comp
);

set_intersectionBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator set_intersection(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result
);

template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Compare>
OutputIterator set_intersection(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result,
    Compare comp
);

set_differenceBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator set_difference(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result
);

template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Compare>
OutputIterator set_difference(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result,
    Compare comp
);

set_symmetric_differenceBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator set_symmetric_difference(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result
);

template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Compare>
OutputIterator set_symmetric_difference(
    InputIterator1 first1, InputIterator1 last1,
    InputIterator2 first2, InputIterator2 last2,
    OutputIterator result,
    Compare comp
);

heap-OperationenBearbeiten

push_heapBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void push_heap(RandomAccessIterator first, RandomAccessIterator last);

template<typename RandomAccessIterator, typename Compare>
void push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);

pop_heapBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void pop_heap(RandomAccessIterator first, RandomAccessIterator last);

template<typename RandomAccessIterator, typename Compare>
void pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);

make_heapBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void make_heap(RandomAccessIterator first, RandomAccessIterator last);

template<typename RandomAccessIterator, typename Compare>
void make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);

sort_heapBearbeiten

// Header: algorithm
template<typename RandomAccessIterator>
void sort_heap(RandomAccessIterator first, RandomAccessIterator last);

template<typename RandomAccessIterator, typename Compare>
void sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);

Minimum und MaximumBearbeiten

minBearbeiten

// Header: algorithm
template<typename T>
const T& min(const T& a, const T& b);

template<typename T, typename Compare>
const T& min(const T& a, const T& b, Compare comp);

maxBearbeiten

// Header: algorithm
template<typename T>
const T& max(const T& a, const T& b);

template<typename T, typename Compare>
const T& max(const T& a, const T& b, Compare comp);

min_elementBearbeiten

// Header: algorithm
template<typename ForwardIterator>
ForwardIterator min_element(ForwardIterator first,  ForwardIterator last);

template<typename ForwardIterator, typename Compare>
ForwardIterator min_element(ForwardIterator first,  ForwardIterator last, Compare comp);

max_elementBearbeiten

// Header: algorithm
template<typename ForwardIterator>
ForwardIterator max_element(ForwardIterator first,  ForwardIterator last);

template<typename ForwardIterator, typename Compare>
ForwardIterator max_element(ForwardIterator first,  ForwardIterator last, Compare comp);

lexicographical_compareBearbeiten

// Header: algorithm
template<typename InputIterator1, typename InputIterator2>
bool lexicographical_compare(
    InputIterator1 first1, InputIterator1  last1,
    InputIterator2 first2, InputIterator2  last2
);

template<typename InputIterator1, typename InputIterator2, typename Compare>
bool lexicographical_compare(
    InputIterator1 first1, InputIterator1  last1,
    InputIterator2 first2, InputIterator2  last2,
    Compare comp
);

PermutationenBearbeiten

next_permutationBearbeiten

// Header: algorithm
template<typename BidirectionalIterator>
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last);

template<typename BidirectionalIterator, typename Compare>
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);

prev_permutationBearbeiten

// Header: algorithm
template<typename BidirectionalIterator>
bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last);

template<typename BidirectionalIterator, typename Compare>
bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);