Answers for "comparator sort in cpp"

C++
2

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;
});
Posted by: Guest on March-09-2022
0

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);
Posted by: Guest on October-25-2021

Code answers related to "comparator sort in cpp"

Browse Popular Code Answers by Language