C++ algorithm is_permutation() function
Example
Find out if a vector is a permutation of another:
vector<int> numbers = {1, 7, 3, 5, 9, 2};
vector<int> other = {9, 7, 5, 3, 2, 1};
if (is_permutation(numbers.begin(), numbers.end(), other.begin())) {
cout << "Permutation found";
} else {
cout << "No permutation found";
}
Try it Yourself »
Definition and Usage
The is_permutation()
function checks if a permutation of a data range can be found in another data range. If a permutation is found then the function returns a boolean value 1, it returns 0 otherwise.
A permutation is a sequence of values that starts at the beginning of the second data range, has the same size and values as the first data range, but the values can be in a different order.
The data ranges are specified by iterators.
Syntax
is_permutation(iterator start, iterator end, iterator other);
Parameter Values
Parameter | Description |
---|---|
start | Required. An iterator pointing to the start of the first data range. |
end | Required. An iterator pointing to the end of the first data range. Elements up to this position will be included, but the element at this position will not be. |
other | Required. An iterator pointing to the start of the second data range. |
Technical Details
Returns: | A boolean value:
|
---|
Related Pages
Read more about data structures in our Data Structures Tutorial.
Read more about iterators in our Iterators Tutorial.
Read more about algorithms in our Algorithms Tutorial.
Read more about booleans in our Booleans Tutorial.