0
下面的代碼給出了分段錯誤,有人能夠啓發我嗎?我想要實現的是按照tv.t的升序或tv.m的降序排列優先級隊列。priority_queue emplace給出分段錯誤
struct tv {
int m;
int c;
int t;
tv(int mm, int cc, int tt): m(mm), c(cc), t(tt) {}
};
bool comp(struct tv & t1 , struct tv & t2) {
if (t1.t == t2.t) {
return t1.m < t2.m;
}
return t1.t > t2.t;
}
int main(int argc, char** argv) {
priority_queue<struct tv, vector<struct tv>, decltype(&comp)> q;
q.emplace(0, 0, 0);
q.emplace(1, 0, 0);
q.emplace(1, 1, 1);
q.emplace(1, 2, 0);
return 0;
}