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 :: string to int arduino 
Cpp :: how to write a hello world program in c++ 
Cpp :: save all output in log file c cpp 
Cpp :: cpp goiver all the map values 
Cpp :: swap values in array c++ 
Cpp :: OPA in expanse 
Cpp :: check if point is left or right of vector 
Cpp :: loop through char in string c++ 
Cpp :: c++ user input 
Cpp :: c++ unordered_map check if key exists 
Cpp :: c++ product of vector 
Cpp :: C++ Multi-line comments 
Cpp :: malloc in c++ 
Cpp :: convert long int to binary string c++ 
Cpp :: how to split a string into words c++ 
Cpp :: delete map elements while iterating cpp 
Cpp :: http.begin() error 
Cpp :: c++ struct with default values 
Cpp :: how to install boost c++ on windows 
Cpp :: how to make a loop in c++ 
Cpp :: Write C++ program to sort an array in ascending order 
Cpp :: all data types in c++ 
Cpp :: sleep c++ 
Cpp :: convert string toupper and tolower in cpp 
Cpp :: glew32.dll was not found 
Cpp :: file c++ 
Cpp :: c++ Sum of all the factors of a number 
Cpp :: check if set contains element c++ 
Cpp :: int main() { 
Cpp :: find the missing number 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =