DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

Custom compare class

If marks of two student is equal give priority to Roll or Math marks or Biology marks we have to tell it to computer .

include

using namespace std;
class Student{
public:
string name ;
int roll ;
int marks ;
Student(string name , int roll , int marks){
this->name = name ;
this->roll =roll ;
this->marks = marks ;
}
};

class cmp{
public:
bool operator()(Student l , Student r )
{
if(l.marks < r.marks)
return true ;
else
return false ;

}
Enter fullscreen mode Exit fullscreen mode

};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue,cmp> pq;
int n ;
cin >> n ;
for(int i = 0 ; i < n ; i++){
string name ;
int roll , marks ;
cin >> name >> roll >> marks ;
Student obj(name,roll , marks) ;
pq.push(obj) ;
}

while(!pq.empty()){
cout << pq.top().name << " " << pq.top().roll << " " << pq.top().marks() << endl ;

}
return 0 ;

}

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay