This content originally appeared on DEV Community and was authored by Mujahida Joynab
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 ;
}
};
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 ;
}
This content originally appeared on DEV Community and was authored by Mujahida Joynab

Mujahida Joynab | Sciencx (2025-02-23T14:17:47+00:00) Custom compare class. Retrieved from https://www.scien.cx/2025/02/23/custom-compare-class/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.