Complete Reverse() function that returns a new character vector containing all contents in the input argument reversed. Ex: If the input vector is: ['a', 'b', 'c'] then the returned vector will be: ['c', 'b', 'a']
Using c++
Reverse vector
Complete Reverse() function that returns a new character vector containing all contents in the input argument reversed.
Ex: If the input vector is:
['a', 'b', 'c']then the returned vector will be:
['c', 'b', 'a']#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// initializing the vector
vector<char> vect = { };
// Printing the vector
cout<<"Reversing a vector by using reverse iterators"<<endl;
cout << "Vector: ";
for (int i = 0; i < vect.size(); i++)
cout << vect[i];
cout << endl;
//reversing the vector
vector<char> v2 (vect.rbegin(),vect.rend());
vect.swap(v2);
// Printing the reversed vector
cout << "Reversed Vector: ";
for (int i = 0; i < vect.size(); i++)
cout << vect[i];
cout << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images