Search
 
SCRIPT & CODE EXAMPLE
 

CPP

comparator in sort c++

bool com_fun(int a,int b){
	if(a<b) return true;
	else return false;
}

sort(arr,arr+n.com_fun);
Comment

sorting using comparator in c++

struct point{
    int weight, position, id;
};
// . . . . . .
// your code
// for sorting using weight 
sort(points.begin(), points.end(), [] (point a, point b){
return a.weight < b.weight;
});


// for sorting using positions
sort(points.begin(), points.end(), [] (point a, point b){
return a.position < b.position;
});
Comment

PREVIOUS NEXT
Code Example
Cpp :: draw rectangle opencv c++ 
Cpp :: c++ add to array 
Cpp :: long to string cpp 
Cpp :: reverse order binary tree in c++ 
Cpp :: quick sort c+++ 
Cpp :: how to declare a 2D vector in c++ of size m*n with value 0 
Cpp :: how do you wait in C++ 
Cpp :: how to specify the number of decimal places in c++ 
Cpp :: c++ get line 
Cpp :: memory leak in cpp 
Cpp :: array to string c++ 
Cpp :: sort vector of strings 
Cpp :: string length in c++ 
Cpp :: c #define 
Cpp :: c++ string conversion operator 
Cpp :: Inner Section Sticky Scroll in elementor 
Cpp :: word equation numbers 
Cpp :: c++ float and double 
Cpp :: c++ Least prime factor of numbers till n 
Cpp :: c++ for loop multiple variables 
Cpp :: resize string c++ 
Cpp :: visual studio getline not working 
Cpp :: accumulate vector c++ 
Cpp :: do while c++ 
Cpp :: C++ Calculating the Mode of a Sorted Array 
Cpp :: loop c++ 
Cpp :: cpp oop 
Cpp :: cmd color text c++ 
Cpp :: google test assert throw 
Cpp :: Character cin(userInput) in c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =