Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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

sort vector in descending order

sort(a.begin(), a.end(), greater<int>());
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

PREVIOUS NEXT
Code Example
Cpp :: create copy constructor c++ 
Cpp :: c++ pi float 
Cpp :: insert only unique values into vector 
Cpp :: c++ hello world 
Cpp :: is power of 2 
Cpp :: could not find the task c c++ active file 
Cpp :: who to include a library c++ 
Cpp :: filling 2d array with 0 c++ 
Cpp :: c++ initialize vector of vector with size 
Cpp :: sizeof operator in c++ 
Cpp :: Reverse Level Order Traversal cpp 
Cpp :: hello world in c/++ 
Cpp :: print duplicate characters from string in c++ 
Cpp :: find kth max and min element in an array 
Cpp :: cpp mutex 
Cpp :: c++ struct constructor 
Cpp :: c++ uint32_t 
Cpp :: compute power of number 
Cpp :: c++ hello world linux 
Cpp :: what is meant by pragma once in c++ 
Cpp :: constructor in cpp 
Cpp :: c ++ splitlines 
Cpp :: stl c++ 
Cpp :: initialize vector 
Cpp :: how to create a c++ templeate 
Cpp :: vector of threads thread pool c++ 
Cpp :: udo apt install dotnet-sdk-5 permission denied 
Cpp :: Translation codeforces in c++ 
Cpp :: string erase 
Cpp :: dequeue c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =