1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <functional> // definition of less
#include <queue>  // definition of priority_queue
#include <iostream>
 
using namespace std;
 
struct Task
{
        int priority;
        friend bool operator < (const Task& t1, const Task& t2);
        Task(int p=0) : priority(p) {}
};
 
bool operator < (const Task& t1, const Task& t2)
{
        return t1.priority < t2.priority;
}
 
int main()
{
        priority_queue<Task> scheduler;
        scheduler.push(Task(3));
        scheduler.push(Task(5));
        scheduler.push(Task(1));
        scheduler.push(Task(1));
        cout<< scheduler.top().priority <<endl;   // output 5
        return 0;
}


출처: http://www.milab.co.kr/


Posted by kkokkal
: