std::stable_partition
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Заголовочный файл <algorithm>
|
||
| template< class BidirIt, class UnaryPredicate > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p ); |
||
Сортирует элементы в диапазоне
[first, last) таким образом, что все элементы, для которых предикат возвращает p true предшествовать элементы, для которых предикат возвращает p false. Относительный порядок элементов сохраняется. Original:
Reorders the elements in the range
[first, last) in such a way that all elements for which the predicate p returns true precede the elements for which predicate p returns false. Relative order of the elements is preserved. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Содержание |
[править] Параметры
| first, last | - | диапазон элементов в порядок
Original: the range of elements to reorder The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| p | - | унарный предикат, который возвращает true если элемент должны быть заказаны до других элементов . Original: if the element should be ordered before other elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. Сигнатура функции-предиката должны быть эквивалентна следующей:
В сигнатуре не обязательно наличие const &, но функция не должна изменять переданный ей объект. | |||||||||
| Требования, накладываемые на типы | |||||||||||
-BidirIt должен соответствовать требованиям ValueSwappable и BidirectionalIterator.
| |||||||||||
-Тип разыменованного BidirIt должен соответствовать требованиям MoveAssignable и MoveConstructible.
| |||||||||||
[править] Возвращаемое значение
Итератор на первый элемент второй группы
Original:
Iterator to the first element of the second group
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Сложность
Именно
last-first применения предиката и в большинстве свопы (last-first)*log(last-first), если недостаточно памяти или линейного количество обменов, если наличии достаточного объема памяти.Original:
Exactly
last-first applications of the predicate and at most (last-first)*log(last-first) swaps if there is insufficient memory or linear number of swaps if sufficient memory is available.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Пример
#include <iostream> #include <algorithm> int main() { std::vector<int> v{0, 0, 3, 0, 2, 4, 5, 0, 7}; std::stable_partition(v.begin(), v.end(), [](int n){return n>0;}); for (int n : v) { std::cout << n << ' '; } std::cout << '\n'; }
Вывод:
3 2 4 5 7 0 0 0 0
[править] См. также
| делит диапазон элементов на две группы Original: divides a range of elements into two groups The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |