The Wayback Machine - https://web.archive.org/web/20180520192951/http://es.cppreference.com:80/w/cpp/algorithm/reverse
Espacios de nombres
Variantes
Acciones

std::reverse

De cppreference.com
< cpp‎ | algorithm

 
 
Biblioteca de algoritmos
Políticas de ejecución (C++17)
Operaciones no modificadoras de secuencia
(C++11)(C++11)(C++11)
(C++17)
Operaciones modificadoras de secuencia
Operaciones en almacenamiento no inicializado
Operaciones de partición
Operaciones de ordenación
Operaciones de búsqueda binaria
Operaciones de set (en rangos ordenados)
Operaciones de pila
(C++11)
Operaciones minimo/maximo
(C++11)
(C++17)
Permutaciones
Operaciones numéricas
Bibliotecas C
 
Definido en la cabecera <algorithm>
template<class BidirIt >
void reverse( BidirIt first, BidirIt last );
Invierte el orden de los elementos en el rango [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.

Contenido

[editar]Parámetros

first, last -
el intervalo de elementos de revertir
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.
Requerimientos de tipo
-
BidirIt debe reunir los requerimientos de BidirectionalIterator.
-
The type of dereferenced BidirIt must meet the requirements of Swappable.

[editar]Valor de retorno

(Ninguno)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar]Posible implementación

template<class BidirIt>void reverse(BidirIt first, BidirIt last){while((first != last)&&(first !=--last)){std::swap(*first++, *last);}}

[editar]Ejemplo

#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';}

Salida:

321 7654

[editar]Complejidad

lineal en la distancia entre first y 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.

[editar]Ver también

crea una copia de un rango que se invierte
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.

(plantilla de función)[editar]
close