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 :: http.begin not working 
Cpp :: multiline comment in c++ 
Cpp :: time function c++ 
Cpp :: random number cpp 
Cpp :: take pieces of a string in c++ 
Cpp :: tuple c++ 
Cpp :: c++ string to int conversion 
Cpp :: What should main() return in C++? 
Cpp :: iteraate through a vector 
Cpp :: random number of 0 or 1 c++ 
Cpp :: do while loop c++ loops continuously 
Cpp :: fstring from float c++ ue4 
Cpp :: how to pass function as a parameter in c++ 
Cpp :: c++ vector pop_back 
Cpp :: how to take space separated input in c++ 
Cpp :: c++ programming language 
Cpp :: strlen in c++ 
Cpp :: c++ reference 
Cpp :: input in c++ 
Cpp :: size of array 
Cpp :: clear qlayout 
Cpp :: c++ pi float 
Cpp :: std vector c++ 
Cpp :: C++ break with for loop 
Cpp :: how to empty an array c++ 
Cpp :: how to get the time in c++ as string 
Cpp :: Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. 
Cpp :: c++ string find example 
Cpp :: copying a set to vector in c++ 
Cpp :: what is meant by pragma once in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =