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 :: second smallest element in array using one loop 
Cpp :: C++ Multilevel Inheritance 
Cpp :: overload operator object function call 
Cpp :: is variable sized array are not allowed in c++? 
Cpp :: qpushbutton clicked connect c++ 
Cpp :: how to install open cv2 in c++ on ubuntu 
Cpp :: nothrow new in cpp 
Cpp :: c++ reverse bits 
Cpp :: Polycarp found a rectangular table consisting of n rows and m columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": codeforces solution 
Cpp :: contains in c++ map 
Cpp :: passing array to the function c++ 
Cpp :: qt get wireless interface name 
Cpp :: rgb(100,100,100,0.5) validation c++ 
Cpp :: sort using comparator anonymous function c++ 
Cpp :: C++ References 
Cpp :: c++ sort cout end 
Cpp :: GCD(x, yz) 
Cpp :: ue4 set size of widget c++ 
Cpp :: c ++ loop 
Cpp :: cosnt cast 
Cpp :: break input stream into words 
Cpp :: convert GLFWwindow* to IntPtr 
Cpp :: c++ call overriden method from constructor 
Cpp :: pycuda install failed microsoft c++ 
Cpp :: how to make a substring after certain position 
Cpp :: subsets of a given array 
Cpp :: 2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++ 
Cpp :: is there anything like vector<intx[100] 
Cpp :: dijkstra algorithm in c++ geeksforgeeks 
Cpp :: http://dcnet.ddns.ma/Connecter_Tuteur 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =