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

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

how to sort a vector in descending order in c++

//Method 1
sort(v.begin(),v.end(),greater<>());
//Method 2
//Multiply the vector with -1 and then sort it and again multiply it with -1.
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

sort vector in reverse order c++

#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> vec = { 7, 3, 5, 1, 9 };
 
    std::sort(vec.rbegin(), vec.rend());
 
    // do anything
 
    return 0;
}
Comment

reverse sort a vector

vector<int> v = { 10, 9, 8, 6, 7, 2, 5, 1 };
   sort(v.begin(), v.end(), greater <>());
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 :: get current directory cpp 
Cpp :: flake8 max line length 
Cpp :: jupyter lab use conda environment 
Cpp :: initialize vector to all zeros c++ 
Cpp :: c++ pause program 
Cpp :: c++ milliseconds 
Cpp :: cpp sample code 
Cpp :: stoi c++ 
Cpp :: remove all element of vector c++ 
Cpp :: c++ check if string contains substring 
Cpp :: compile multiple files C++ linux 
Cpp :: leveling system c++ 
Cpp :: c++ converting centimeters to kilometers 
Cpp :: write a code that adds two number 
Cpp :: c++ nth substr 
Cpp :: C++ std::async wait is taking forever 
Cpp :: perulangan c++ 
Cpp :: hi cpp 
Cpp :: stl for sorting in c++ 
Cpp :: c++ read file to char buffer 
Cpp :: c++ remove space from string 
Cpp :: char vector to string c++ 
Cpp :: find character in string c++ 
Cpp :: hello world C++, C plus plus hello world 
Cpp :: c++ area of triangle 
Cpp :: how to get input in cpp 
Cpp :: how to make for loop in c++ 
Cpp :: how to read a comma delimited file into an array c++ 
Cpp :: cpp macro 
Cpp :: c++ string comparison 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =