#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct job{
int job_no;
int deadline;
int profit;
};
typedef vector<job> JOB;
int COMP_BY_DEADLINE(job x, job y){
return x.deadline<y.deadline; // x보다 y가 더 크도록 정렬 (increasing order)
}
int COMP_BY_PROFIT(job x, job y){
return x.profit>y.profit; // x가 y보다 더 크도록 정렬 (decreasing order)
}
int COMP_CUSTOM(job x, job y){
if(x.deadline == y.deadline){
return x.job_no < y.job_no;
}
return x.deadline<y.deadline;
}
job CREATE_job(int job_no, int deadline, int profit){
job j;
j.job_no = job_no;
j.deadline = deadline;
j.profit = profit;
return j;
}
int main(){
JOB jobs;
jobs.push_back(CREATE_job(1,3,40));
jobs.push_back(CREATE_job(2,2,50));
jobs.push_back(CREATE_job(3,3,20));
jobs.push_back(CREATE_job(4,1,15));
sort(jobs.begin(), jobs.end(), COMP_BY_PROFIT);
// # 정렬결과
// # 50 40 20 15
sort(jobs.begin(), jobs.end(), COMP_BY_DEADLINE);
// # 정렬결과
// # 1 2 3 3
sort(jobs.begin(), jobs.end(), COMP_CUSTOM);
// # 정렬결과
// # 1 2 3(job_no: 1) 3(job_no: 3)
}