Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

C++ reverse vector

// 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;
}
Comment

how to reverse a vector

//vector<int> A;
reverse(A.begin(),A.end());
Comment

c++ reverse part of vector

//Reverse vector partially (from index x to index y)
reverse(v.begin()+x, v.begin()+y+1);
Comment

c++ reverse vector

#include <vector>
#include <algorithm>

int main() {
  std::vector<int> a;
  std::reverse(a.begin(), a.end());
  return 0;
}
Comment

reverse in vector c++

reverse(start_index, last_index);
Comment

PREVIOUS NEXT
Code Example
Cpp :: sstream c++ 
Cpp :: Decision Making in C / C++ (if , if..else, Nested if, if-else-if ) 
Cpp :: problem category codechef solution in c++ 
Cpp :: std::enable_shared_from_this include 
Cpp :: cpprestsdk send file 
Cpp :: rgb type def 
Cpp :: Numbers Histogram in c++ 
Cpp :: how atan work c++ 
Cpp :: error C2011 
Cpp :: Maximum Weight Difference codechef solution c++ 
Cpp :: c++ *agrs 
Cpp :: solve problem of getline 
Cpp :: c++ online 
Cpp :: whatsup 
Cpp :: c++ copy vector 
Cpp :: print all substrings in c++ 
Cpp :: C++ using a member function of a class to pass parameters to a thread 
Cpp :: static member fn , instance 
Cpp :: overloading templates in cpp 
Cpp :: c++ conditional typedef 
Cpp :: stl map 
Cpp :: c++ to mips assembly converter 
Cpp :: how initilaize deffult value to c++ class 
Cpp :: ue4 c++ bool to text 
Cpp :: c++ regex to validate indian phone number pattern 
Cpp :: sort c++ stl 
Cpp :: how to change the default camera speed values opengl 
Cpp :: how to print std::string 
Cpp :: ros pointcloud2 read_points c++ 
Cpp :: 3 conditions for a while loop c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =