C++ algorithm reverse_copy() function
Example
Create a copy of a vector with the elements in reverse order:
vector<int> numbers = {1, 3, 5, 7, 2, 9};
vector<int> newnumbers(6);
reverse_copy(numbers.begin(), numbers.end(), newnumbers.begin());
for (int number : newnumbers) {
cout << number << " ";
}
Try it Yourself »
Definition and Usage
The reverse_copy()
function creates a copy of a data range with the elements in reverse order.
The range of data is specified by iterators.
Syntax
reverse_copy(iterator start, iterator end, iterator destination);
Parameter Values
Parameter | Description |
---|---|
start | Required. An iterator pointing to the start of the data range. |
end | Required. An iterator pointing to the end of the data range. Elements up to this position will be included, but the element at this position will not be. |
deatination | Required. An iterator pointing to the start of the data range that the data will be copied to. |
Technical Details
Returns: | An iterator pointing to the end of the destination data range. |
---|
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.