Answers for "reverse a vector c++"

C++
21

c++ reverse vector

#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;
}
Posted by: Guest on April-26-2020
9

how to sort a vector in reverse c++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
   vector<int> v = { 10, 9, 8, 6, 7, 2, 5, 1 };
   sort(v.begin(), v.end(), greater <>());
}
Posted by: Guest on June-21-2020
1

how to reverse a vector

//vector<int> A;
reverse(A.begin(),A.end());
Posted by: Guest on May-15-2020
1

std::reverse

std::vector<int> v{1,2,3};
    std::reverse(std::begin(v), std::end(v));
Posted by: Guest on May-23-2020
1

c++ reverse part of vector

//Reverse vector partially (from index x to index y)
reverse(v.begin()+x, v.begin()+y+1);
Posted by: Guest on October-05-2020
0

reverse a vector c++

// Given the vector
vector<int> a = { 1, 45, 54, 71, 76, 12 };

// Reverse the vector
reverse(a.begin(), a.end());
Posted by: Guest on May-23-2021

Browse Popular Code Answers by Language