// C++
#include <iostream>
#include <queue>
using namespace std;
struct Student
{
int id;
int math;
int eng;
Student(int num, int math, int eng) : id(num), math(math), eng(eng) {}
// < 연산자 오버로딩하여 우선순위 조정
// id가 작은 것이 우선순위
bool operator< (const Student s) const
{
return this->id > s.id;
}
};
int main()
{
priority_queue<Student> pQueue;
pQueue.push(Student(5, 80, 50));
pQueue.push(Student(3, 60, 30));
pQueue.push(Student(1, 50, 80));
pQueue.push(Student(2, 65, 95));
pQueue.push(Student(4, 70, 100));
// 큐가 비어있지 않으면 실행
while (!pQueue.empty())
{
// 우선순위가 가장 높은 데이터 반환
// 데이터가 삭제되지는 않음
Student student = pQueue.top();
// 우선순위가 가장 높은 데이터 삭제
pQueue.pop();
cout << "우선순위가 가장 높은 데이터" << endl;
cout << "학번 : "<<student.id << endl;
cout << "math : "<<student.math << endl;
cout << "eng : "<<student.eng << endl;
}
return 0;
}