How to write proper comparators in C++

struct val{
	mutable int deg=0;
	ll wgt=0;

	bool operator<(const val& t) const{
        if(this->deg != t.deg){
	        return (this->deg > t.deg);
        }
        return (this->wgt > t.wgt);
    }
};

I wrote this code by refering to internet but I don’t know how to write such comparators, etc. for structs and custom sorting functions. So please tell some good resources which I can refer for this.

@cubefreak777 Please help

Have you referred to this?
https://www.cprogramming.com/tutorial/operator_overloading.html

2 Likes

Seems good. Thank you