#include <bits/stdc++.h> // Vector
#include <algorithm> // Reverse
using namespace std;
int main()
{
vector<int> nums{4,1,2,1,2};
reverse(nums.begin(), nums.end());
return 0;
}
// C++ program to reverse Vector
// using reverse() in STL
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Get the vector
vector<int> a = { 1, 45, 54, 71, 76, 12 };
// Print the vector
cout << "Vector: ";
for (int i = 0; i < a.size(); i++)
cout << a[i] << " ";
cout << endl;
// Reverse the vector
reverse(a.begin(), a.end());
// Print the reversed vector
cout << "Reversed Vector: ";
for (int i = 0; i < a.size(); i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
//vector<int> A;
reverse(A.begin(),A.end());
//Reverse vector partially (from index x to index y)
reverse(v.begin()+x, v.begin()+y+1);
#include <vector>
#include <algorithm>
int main() {
std::vector<int> a;
std::reverse(a.begin(), a.end());
return 0;
}
reverse(start_index, last_index);
Code Example |
---|
Cpp :: set size in c++ |
Cpp :: swap in cpp |
Cpp :: map in cpp |
Cpp :: c++ average vector |
Cpp :: access last element of set c++ |
Cpp :: stl function to reverse an array |
Cpp :: how to find even and odd numbers in c++ |
Cpp :: sum array c++ |
Cpp :: tuple vector c++ |
Cpp :: c++ vector |
Cpp :: double array c++ |
Cpp :: c++ find index of element in array |
Cpp :: find positive number factorial in C++ |
Cpp :: set of vectors c++ |
Cpp :: how to access a vector member by its index |
Cpp :: draw line sfml |
Cpp :: create a vector of size n in c++ |
Cpp :: converting char to integer c++ |
Cpp :: how to concatinate two strings in c++ |
Cpp :: arduino falling edge |
Cpp :: c++ insert hashmap |
Cpp :: hide window c++ |
Cpp :: c++ write string |
Cpp :: memset in cpp |
Cpp :: merge sort in descending order c++ |
Cpp :: assign value to a pointer |
Cpp :: compile and run cpp file on mac c++ |
Cpp :: substring function in c++ |
Cpp :: C++ Initialization of three-dimensional array |
Cpp :: in built function to find MSB in cpp |