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 :: power function c++ 
Cpp :: 2d vector in cpp 
Cpp :: gettimeofday header file 
Cpp :: remove first occurrence of value from vector c++ 
Cpp :: c preprocessor operations 
Cpp :: c++ string split 
Cpp :: how to initialize vector 
Cpp :: c++ char array size 
Cpp :: sort vector c++ 
Cpp :: c++ replace 
Cpp :: array length c++ 
Cpp :: quicksort geeksforgeeks 
Cpp :: all permutations with repetition C++ 
Cpp :: how to remove first element from vector c++ 
Cpp :: c++ for loop multiple variables 
Cpp :: array of struct in c++ 
Cpp :: c++ remove chars from string 
Cpp :: c++ changing string to double 
Cpp :: how to make a function in c++ 
Cpp :: visual studio cpp compiler 
Cpp :: toString method in c++ using sstream 
Cpp :: how to change the value of a key in hashmp in c++ 
Cpp :: use of strstr in c++ 
Cpp :: why use python 
Cpp :: rethrow exception c++ 
Cpp :: c++ random int troll 
Cpp :: closing a ifstream file c++ 
Cpp :: C++ program to print all possible substrings of a given string 
Cpp :: cpp undefined reference to function 
Cpp :: how to make a pointer point to a the last value in an array 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =