Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a vector to another vector in reverse order

Tags:

c++

stl

vector

I am new in C++.
I need to copy a vector in reverse order to another vector.

Here's how i did it :

int temp[] = {3, 12, 17};

vector<int>v(temp, temp+3);

vector<int>n_v;

n_v=v;
reverse(n_v.begin(), n_v.end()); //Reversing new vector

Is there any simple way to copy a vector in reverse order to another vector in STL?

like image 765
Black Swan Avatar asked Nov 30 '22 00:11

Black Swan


1 Answers

Simply just do this:

vector<int>n_v (v.rbegin(), v.rend());
like image 187
Ali Akber Avatar answered Dec 04 '22 13:12

Ali Akber