[ Web Proxy ]
URL:
Viewing: http://pt.cppreference.com/cpp/algorithm/is_permutation [Back]  [Original]

std::is_permutation - cppreference.com
cppreference.com
Espaos nominais
Variantes

std::is_permutation

De cppreference.com

<metanoindex/>

 
 
Biblioteca algoritmo
Funes
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
No modificar operaes de seqncia
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 operaes de seqncia
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 operaes
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.
Operaes de classificao (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.
Binrios operaes 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 operaes (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.
Operaes 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.
Mnimo / mximo de operaes
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.
Operaes numricas
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.
 
<tbody> </tbody>
Definido no cabealho <algorithm>
template< class ForwardIt1, class ForwardIt2 > bool is_permutation( ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first );
(1) (desde C++11)
template< class ForwardIt1, class ForwardIt2, class BinaryPredicate > bool is_permutation( ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, BinaryPredicate p );
(2) (desde C++11)
Retorna true se existe uma permutao dos elementos na [first1, last1) faixa que faz com que a gama igual a da gama de d_first. A primeira verso utiliza operator== para a igualdade, a segunda verso utiliza o p predicado binrio
Original:
Returns true if there exists a permutation of the elements in the range [first1, last1) that makes that range equal to the range beginning at d_first. The first version uses operator== for equality, the second version uses the binary predicate p
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parmetros

first, last -
a gama de elementos para comparar
Original:
the range of elements to compare
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d_first -
o incio da segunda gama de comparar
Original:
the beginning of the second range to compare
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - binary predicate which returns true if the elements should be treated as equal.

The signature of the predicate function should be equivalent to the following:

bool pred(const Type1 &a, const Type2 &b);

The signature does not need to have const &, but the function must not modify the objects passed to it.
The types Type1 and Type2 must be such that objects of types ForwardIt1 and ForwardIt2 can be dereferenced and then implicitly converted to Type1 and Type2 respectively.

Type requirements
-
ForwardIt1, ForwardIt2 must meet the requirements of ForwardIterator.

Valor de retorno

true se o [first, last) intervalo uma permutao de incio escala em d_first.
Original:
true if the range [first, last) is a permutation of the range beginning at d_first.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complexidade

Na maioria das aplicaes de O(N2) do predicado, ou exatamente N se as seqncias j so iguais, onde N=std::distance(first, last).
Original:
At most O(N2) applications of the predicate, or exactly N if the sequences are already equal, where N=std::distance(first, last).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Possvel implementao

template<class ForwardIt1, class ForwardIt2>
bool is_permutation(ForwardIt1 first, ForwardIt1 last,
                    ForwardIt2 d_first)
{
   // skip common prefix
   std::tie(first, d_first) = std::mismatch(first, last, d_first);
   // iterate over the rest, counting how many times each element
   // from [first, last) appears in [d_first, d_last)
   if (first != last) {
       ForwardIt2 d_last = d_first;
       std::advance(d_last, std::distance(first, last));
       for (ForwardIt1 i = first; i != last; ++i) {
            if (i != std::find(first, i, *i)) continue; // already counted this *i

            auto m = std::count(d_first, d_last, *i);
            if (m==0 || std::count(i, last, *i) != m) {
                return false;
            }
        }
    }
    return true;
}

Exemplo

#include <algorithm>
#include <vector>
#include <iostream>
int main()
{
    std::vector<int> v1{1,2,3,4,5};
    std::vector<int> v2{3,5,4,1,2};
    std::cout << "3,5,4,1,2 is a permutation of 1,2,3,4,5? "
              << std::boolalpha
              << std::is_permutation(v1.begin(), v1.end(), v2.begin()) << '\n';

    std::vector<int> v3{3,5,4,1,1};
    std::cout << "3,5,4,1,1 is a permutation of 1,2,3,4,5? "
              << std::boolalpha
              << std::is_permutation(v1.begin(), v1.end(), v3.begin()) << '\n';
}

Sada:

3,5,4,1,2 is a permutation of 1,2,3,4,5? true
3,5,4,1,1 is a permutation of 1,2,3,4,5? false

Veja tambm

generates the next greater lexicographic permutation of a range of elements
(modelo de funo) [edit]
generates the next smaller lexicographic permutation of a range of elements
(modelo de funo) [edit]

Web Proxy Viewer  |  New URL  |  Original Page