回答編集履歴
1
追記
test
CHANGED
@@ -69,3 +69,79 @@
|
|
69
69
|
}
|
70
70
|
|
71
71
|
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
[追記] 比較関数を与えた版
|
76
|
+
|
77
|
+
```C++
|
78
|
+
|
79
|
+
#include <iostream>
|
80
|
+
|
81
|
+
#include <queue>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
struct record {
|
86
|
+
|
87
|
+
int ID1;
|
88
|
+
|
89
|
+
int ID2;
|
90
|
+
|
91
|
+
int value;
|
92
|
+
|
93
|
+
};
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
struct greater_record {
|
98
|
+
|
99
|
+
bool operator()(const record& x, const record& y) const {
|
100
|
+
|
101
|
+
return x.value > y.value;
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
};
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
std::ostream& operator<<(std::ostream& stream, const record& r) {
|
110
|
+
|
111
|
+
return stream << r.ID1 << '/' << r.ID2 << '/' << r.value;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
int main() {
|
118
|
+
|
119
|
+
std::priority_queue<record, std::vector<record>, greater_record> q;
|
120
|
+
|
121
|
+
for ( int i=0; i < 30; ++i ) {
|
122
|
+
|
123
|
+
record r;
|
124
|
+
|
125
|
+
r.ID1 = i % 7;
|
126
|
+
|
127
|
+
r.ID2 = i % 5;
|
128
|
+
|
129
|
+
r.value = i % 3;
|
130
|
+
|
131
|
+
q.push(r);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
while ( !q.empty() ) {
|
138
|
+
|
139
|
+
std::cout << q.top() << std::endl;
|
140
|
+
|
141
|
+
q.pop();
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
```
|