Espaces de noms
Variantes
Actions

std::rotate

De cppreference.com
< cpp‎ | algorithm

 
 
Bibliothèque d'algorithmes
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Non-modification de la séquence des opérations
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modification de la séquence des opérations
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Des opérations de partitionnement
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Opérations de tri (sur les gammes triés)
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Opérations binaires de recherche (sur les gammes triés)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Définir les opérations (sur les gammes triés)
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Opérations Heap
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Minimum / maximum de fonctionnement
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Opérations numériques
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bibliothèque C
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Déclaré dans l'en-tête <algorithm>
template<class ForwardIt >

void rotate( ForwardIt first, ForwardIt n_first, ForwardIt last );
template<class ForwardIt >

ForwardIt rotate( ForwardIt first, ForwardIt n_first, ForwardIt last );
(avant C++11)

(depuis C++11)
Echange les éléments dans la gamme [first, last) de telle manière, que l'élément de n_first devient le premier élément de la nouvelle gamme n_first - 1 et devient le dernier élément .
Original:
Swaps the elements in the range [first, last) in such a way, that the element n_first becomes the first element of the new range and n_first - 1 becomes the last element.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Sommaire

[modifier]Paramètres

first, last -
l'ensemble d'éléments en rotation
Original:
the range of elements to rotate
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n_first -
l'élément à déplacer vers le début de la nouvelle plage
Original:
the element to move to the beginning of the new range
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Type requirements
-
ForwardIt must meet the requirements of ValueSwappable and ForwardIterator.
-
The type of dereferenced ForwardIt must meet the requirements of MoveAssignable and MoveConstructible.

[modifier]Retourne la valeur

(Aucun) (avant C++11)
Original:
(none) (avant C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
L'itérateur égale à first + (last - n_first) (depuis C++11)
Original:
The iterator equal to first + (last - n_first) (depuis C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier]Complexité

linéaire de la distance entre first et last
Original:
linear in the distance between first and last
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier]Mise en œuvre possible

template<class ForwardIt>void rotate(ForwardIt first, ForwardIt n_first, ForwardIt last){ ForwardIt next = n_first;while(first != next){std::swap(*first++, *next++);if(next == last){ next = n_first;}elseif(first == n_first){ n_first = next;}}}

[modifier]Exemple

std :: rotate est un élément commun à de nombreux algorithmes. Cet exemple illustre le tri par insertion en C + +
Original:
std::rotate is a common building block in many algorithms. This example demonstrates insertion sort in C++
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <vector>#include <iostream>#include <algorithm>   int main(){std::vector<int> v{2, 4, 2, 0, 5, 10, 7, 3, 7, 1};   std::cout<<"before sort: ";for(int n: v)std::cout<< n <<' ';std::cout<<'\n';   // insertion sortfor(auto i = v.begin(); i != v.end();++i){ std::rotate(std::upper_bound(v.begin(), i, *i), i, i+1);}   std::cout<<"after sort: ";for(int n: v)std::cout<< n <<' ';std::cout<<'\n';   // simple rotation to the left std::rotate(v.begin(), v.begin()+1, v.end());   std::cout<<"simple rotate left  : ";for(int n: v)std::cout<< n <<' ';std::cout<<'\n';   // simple rotation to the right std::rotate(v.rbegin(), v.rbegin()+1, v.rend());   std::cout<<"simple rotate right : ";for(int n: v)std::cout<< n <<' ';std::cout<<'\n';   }

Résultat :

before sort: 2 4 2 0 5 10 7 3 7 1 after sort: 0 1 2 2 3 4 5 7 7 10 simple rotate left : 1 2 2 3 4 5 7 7 10 0 simple rotate right: 0 1 2 2 3 4 5 7 7 10

[modifier]Voir aussi

les copies et les faire pivoter une gamme d'éléments
Original:
copies and rotate a range of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction générique)[edit]
close