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