std::reverse
Aus 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. |
definiert in Header <algorithm>
|
||
template< class BidirIt > void reverse( BidirIt first, BidirIt last ); |
||
Kehrt die Reihenfolge der Elemente im Bereich
[first, last)
.Original:
Reverses the order of the elements in the range
[first, last)
.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.
Inhaltsverzeichnis |
[Bearbeiten] Parameter
first, last | - | das Spektrum der Elemente umzukehren
Original: the range of elements to reverse The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-BidirIt must meet the requirements of BidirectionalIterator .
| ||
-The type of dereferenced BidirIt must meet the requirements of Swappable .
|
[Bearbeiten] Rückgabewert
(None)
Original:
(none)
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.
[Bearbeiten] Mögliche Implementierung
template<class BidirIt> void reverse(BidirIt first, BidirIt last) { while ((first != last) && (first != --last)) { std::swap(*first++, *last); } } |
[Bearbeiten] Beispiel
#include <vector> #include <iostream> #include <algorithm> int main(int argc, char** argv) { std::vector<int> v({1,2,3}); std::reverse(std::begin(v), std::end(v)); std::cout << v[0] << v[1] << v[2] << '\n'; int a[] = {4, 5, 6, 7}; std::reverse(&a[0], &a[4]); std::cout << a[0] << a[1] << a[2] << a[3] << '\n'; }
Output:
321 7654
[Bearbeiten] Komplexität
linear im Abstand
first
und 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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Siehe auch
eine Kopie von einem Bereich, der umgekehrt ist Original: creates a copy of a range that is reversed The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) |