Espaços nominais
Variantes
Acções

Diferenças entre edições de "cpp/algorithm/reverse"

Da cppreference.com
< cpp‎ | algorithm
m (uma edição: Translate from the English version)
m (r2.7.3) (Robô: A adicionar: de, en, fr, it, ja, zh)
Linha 65: Linha 65:
 
{{dcl list end}}
 
{{dcl list end}}
  
 +
 +
 
[[es:cpp/algorithm/reverse]]
 
[[es:cpp/algorithm/reverse]]
 +
 +
 +
 
[[ru:cpp/algorithm/reverse]]
 
[[ru:cpp/algorithm/reverse]]
 +

Revisão das 18h42min de 2 de novembro de 2012

 
 
Biblioteca algoritmo
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Não modificar operações de seqüência
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.
Modificando operações de seqüência
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.
Particionamento operações
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.
Operações de classificação (em intervalos ordenados)
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.
Binários operações de busca (em intervalos ordenados)
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.
Definir operações (em intervalos ordenados)
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.
Operações de pilha
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.
Mínimo / máximo de operações
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.
Operações numéricas
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.
C biblioteca
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.
 
Defined in header <algorithm>
template< class BidirIt >
void reverse( BidirIt first, BidirIt last );
Inverte a ordem dos elementos no [first, last) gama.
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.

Índice

Parâmetros

first, last -
o intervalo de elementos de reverter
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.

Valor de retorno

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

Possível implementação

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

Exemplo

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

Saída:

321
7654

Complexidade

linear, em que a distância entre first e 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.

Veja também

Predefinição:cpp/algorithm/dcl list reverse copy