Przestrzenie nazw
Warianty
Działania

Biblioteka algorytmów

Z cppreference.com
< cpp
 
 
 

Biblioteka algorytmów definiuje funkcje różnorodnych zastosowań (m.in. przeszukiwanie, sortowanie, przeliczanie, manipulowanie) operujące na przedziałach elementów. Należy zwrócić uwagę, że przedziały są zdefiniowane jako [first, last) gdzie last odnosi się do elementu za ostatnim elementem, na którym będą wykonywane operacje.

Spis treści

Constrained algorithms

C++20 provides constrained versions of most algorithms in the namespace std::ranges. In these algorithms, a range can be specified as either an Iterator-Sentinel pair or as a single Range argument, and projections and pointer-to-member callables are supported. Additionally, the return types of most algorithms have been changed to return all potentially useful information computed during the execution of the algorithm.

The header <iterator> provides a set of concepts and related utilities designed to ease constraining common algorithm operations.

(od C++20)


Execution policies

Most algorithms have overloads that accept execution policies. The standard library algorithms support three execution policies: sequential, parallel, and parallel+vector, and the library provides corresponding execution policy types and objects. Users may select an execution policy statically by invoking a parallel algorithm with an execution policy object of the corresponding type: std::execution::seq, std::execution::par, or std::execution::par_unseq.

Standard library implementations (but not the users) may define additional execution policies as an extension. The semantics of parallel algorithms invoked with an execution policy object of implementation-defined type is implementation-defined.

Zdefiniowane w nagłówku <execution>
Defined in namespace std::execution
execution policy types
(klasa)[edit]
(C++17)(C++17)(C++17)
global execution policy objects
(stała)[edit]
Defined in namespace std
test whether a class represents an execution policy
(szablon klasy)[edit]
(od C++17)
Operacje niemodyfikujące elementów
Zdefiniowane w nagłówku <algorithm>
(C++11)(C++11)(C++11)
sprawdza, czy predykat zwraca true dla wszystkich, któregokolwiek albo żadnego z elementów w przedziale
(szablon funkcji)[edit]
applies a function to a range of elements
(szablon funkcji)[edit]
(C++17)
applies a function object to the first n elements of a sequence
(szablon funkcji)[edit]
zwraca liczbę elementów spełniających podane kryteria
(szablon funkcji)[edit]
znajduje pierwszą pozycję, na której dwa przedziały się różnią
(szablon funkcji)[edit]
znajduje pierwszy element spełniający podane kryteria
(szablon funkcji)[edit]
znajduje ostatnie wystąpienie ciągu elementów w przedziale
(szablon funkcji)[edit]
szuka któregokolwiek ze zbioru elementów
(szablon funkcji)[edit]
znajduje pierwsze dwa sąsiadujące elementy, które są sobie równe (albo spełniają predukat)
(szablon funkcji)[edit]
szuka zadanego ciągu elementów
(szablon funkcji)[edit]
szuka w przedziale n następujących po sobie kopii elementu
(szablon funkcji)[edit]
Operacje modyfikujące elementy
Zdefiniowane w nagłówku <algorithm>
Zdefiniowane w nagłówku <algorithm>
kopiuje przedział elementów do nowej lokalizacji
(szablon funkcji)[edit]
(C++11)
kopiuje zadaną liczbę elementów do nowej lokalizacji
(szablon funkcji)[edit]
kopiuje przedział elementów w odwrotnej kolejności
(szablon funkcji)[edit]
(C++11)
przenosi przedział elementów do nowej lokalizacji
(szablon funkcji)[edit]
przenosi przedział elementów do nowej lokalizacji w odwrotnej kolejności
(szablon funkcji)[edit]
przypisuje przez kopiowanie(ang) zadaną wartość do każdego elementu w przedziale
(szablon funkcji)[edit]
przypisuje przez kopiowanie(ang) zadaną wartość do N elementów w przedziale
(szablon funkcji)[edit]
applies a function to a range of elements
(szablon funkcji)[edit]
przypisuje wynik kolejnych wywołań funkcji do wszystkich elementów w przedziale
(szablon funkcji)[edit]
przypisuje wynik kolejnych wywołań funkcji do N elementów w przedziale
(szablon funkcji)[edit]
usuwa elementy spełniające podane kryteria
(szablon funkcji)[edit]
kopiuje przedział elementów, pomijając te spełniające podane kryteria
(szablon funkcji)[edit]
zastępuje wszystkie wartości spełniające podane kryteria inną wartością
(szablon funkcji)[edit]
kopiuje przedział elementów, zastępując elementy spełniające podane kryterium inną wartością
(szablon funkcji)[edit]
zamienia ze sobą wartości dwóch obiektów
(szablon funkcji)[edit]
zamienia ze sobą dwa przedziały elementów
(szablon funkcji)[edit]
zamienia ze sobą elementy wskazywane przez dwa iteratory
(szablon funkcji)[edit]
odwraca kolejność elementów w przedziale
(szablon funkcji)[edit]
kopiuje przedział elementów, odwracając przy tym kolejność elementów
(szablon funkcji)[edit]
przesuwa kolejność elementów w przedziale
(szablon funkcji)[edit]
kopiuje przedział elementów, przesuwając ich kolejność
(szablon funkcji)[edit]
shifts elements in a range
(szablon funkcji)[edit]
(do C++17)(C++11)
losowo miesza kolejność elementów w przedziale
(szablon funkcji)[edit]
(C++17)
selects n random elements from a sequence
(szablon funkcji)[edit]
usuwa następujące po sobie duplikaty elementów w podanym przedziale
(szablon funkcji)[edit]
kopiuje przedział elementów, pomijając następujące po sobie duplikaty
(szablon funkcji)[edit]
Operacje rozdzielające
Zdefiniowane w nagłówku <algorithm>
determines if the range is partitioned by the given predicate
(szablon funkcji)[edit]
divides a range of elements into two groups
(szablon funkcji)[edit]
copies a range dividing the elements into two groups
(szablon funkcji)[edit]
divides elements into two groups while preserving their relative order
(szablon funkcji)[edit]
locates the partition point of a partitioned range
(szablon funkcji)[edit]
Operacje sortujące
Zdefiniowane w nagłówku <algorithm>
(C++11)
checks whether a range is sorted into ascending order
(szablon funkcji)[edit]
finds the largest sorted subrange
(szablon funkcji)[edit]
turns a max heap into a range of elements sorted in ascending order
(szablon funkcji)[edit]
sorts the first N elements of a range
(szablon funkcji)[edit]
copies and partially sorts a range of elements
(szablon funkcji)[edit]
sorts a range of elements while preserving order between equal elements
(szablon funkcji)[edit]
partially sorts the given range making sure that it is partitioned by the given element
(szablon funkcji)[edit]
Operacje przeszukiwania binarnego (na posortowanych przedziałach)
Zdefiniowane w nagłówku <algorithm>
returns an iterator to the first element not less than the given value
(szablon funkcji)[edit]
returns an iterator to the first element greater than a certain value
(szablon funkcji)[edit]
determines if an element exists in a certain range
(szablon funkcji)[edit]
returns range of elements matching a specific key
(szablon funkcji)[edit]
Inne operacje na posortowanych przedziałach
Zdefiniowane w nagłówku <algorithm>
merges two sorted ranges
(szablon funkcji)[edit]
merges two ordered ranges in-place
(szablon funkcji)[edit]
Operacje na zbiorach (lub posortowanych przedziałach)
Zdefiniowane w nagłówku <algorithm>
returns true if one set is a subset of another
(szablon funkcji)[edit]
computes the difference between two sets
(szablon funkcji)[edit]
computes the intersection of two sets
(szablon funkcji)[edit]
computes the symmetric difference between two sets
(szablon funkcji)[edit]
computes the union of two sets
(szablon funkcji)[edit]
Operacje kopcowe
Zdefiniowane w nagłówku <algorithm>
(C++11)
checks if the given range is a max heap
(szablon funkcji)[edit]
finds the largest subrange that is a max heap
(szablon funkcji)[edit]
creates a max heap out of a range of elements
(szablon funkcji)[edit]
adds an element to a max heap
(szablon funkcji)[edit]
removes the largest element from a max heap
(szablon funkcji)[edit]
turns a max heap into a range of elements sorted in ascending order
(szablon funkcji)[edit]
Operacje minimum/maximum
Zdefiniowane w nagłówku <algorithm>
returns the greater of the given values
(szablon funkcji)[edit]
returns the largest element in a range
(szablon funkcji)[edit]
returns the smaller of the given values
(szablon funkcji)[edit]
returns the smallest element in a range
(szablon funkcji)[edit]
(C++11)
returns the smaller and larger of two elements
(szablon funkcji)[edit]
returns the smallest and the largest elements in a range
(szablon funkcji)[edit]
(C++17)
clamps a value between a pair of boundary values
(szablon funkcji)[edit]
Operacje porównujące
Zdefiniowane w nagłówku <algorithm>
determines if two sets of elements are the same
(szablon funkcji)[edit]
returns true if one range is lexicographically less than another
(szablon funkcji)[edit]
compares two values using three-way comparison
(szablon funkcji)[edit]
test whether a class represents an execution policy
(szablon klasy)[edit]
Operacje na permutacjach
Zdefiniowane w nagłówku <algorithm>
determines if a sequence is a permutation of another sequence
(szablon funkcji)[edit]
generates the next greater lexicographic permutation of a range of elements
(szablon funkcji)[edit]
generates the next smaller lexicographic permutation of a range of elements
(szablon funkcji)[edit]
Operacje numeryczne
Zdefiniowane w nagłówku <numeric>
(C++11)
wypełnia zakres z kolejnymi przyrostami wartości początkowej
(szablon funkcji)[edit]
suma elementów z zadanego zakresu
(szablon funkcji)[edit]
oblicza iloczyn skalarny dwóch elementów o podanym zakresie
(szablon funkcji)[edit]
oblicza różnice między sąsiednimi elementami w zakresie
(szablon funkcji)[edit]
oblicza sumę częściową z podanego zakresu
(szablon funkcji)[edit]
(C++17)
podobnie do std::accumulate, z wyjątkiem kolejności
(szablon funkcji)[edit]
podobne do std::partial_sum, z wyjątkiem wyklucza i-element wejściowy z i-tej sumy
(szablon funkcji)[edit]
podobnie do std::partial_sum, zawiera ith element wejściowy w i-tej sumie
(szablon funkcji)[edit]
stosuje funktor, a następnie stosuje std::reduce
(szablon funkcji)[edit]
stosuje funktor, a następnie oblicza std::exclusive_scan
(szablon funkcji)[edit]
stosuje funktor, a następnie oblicza std::inclusive_scan
(szablon funkcji)[edit]
Operacje na niezainicjalizowanej pamięci
Zdefiniowane w nagłówku <memory>
copies a range of objects to an uninitialized area of memory
(szablon funkcji)[edit]
copies a number of objects to an uninitialized area of memory
(szablon funkcji)[edit]
copies an object to an uninitialized area of memory, defined by a range
(szablon funkcji)[edit]
copies an object to an uninitialized area of memory, defined by a start and a count
(szablon funkcji)[edit]
moves a range of objects to an uninitialized area of memory
(szablon funkcji)[edit]
moves a number of objects to an uninitialized area of memory
(szablon funkcji)[edit]
constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(szablon funkcji)[edit]
constructs objects by default-initialization in an uninitialized area of memory, defined by a start and a count
(szablon funkcji)[edit]
constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(szablon funkcji)[edit]
constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count
(szablon funkcji)[edit]
(C++17)
destroys an object at a given address
(szablon funkcji)[edit]
(C++17)
destroys a range of objects
(szablon funkcji)[edit]
(C++17)
destroys a number of objects in a range
(szablon funkcji)[edit]
Biblioteka C
Zdefiniowane w nagłówku <cstdlib>
sorts a range of elements with unspecified type
(funkcja)[edit]
searches an array for an element of unspecified type
(funkcja)[edit]


[edytuj]Zobacz także

C documentation for Algorithms
close