#include <iostream> #include <queue> // 一ケタ目だけを比較する struct less_digit { bool operator()(int x, int y) const { return (x%10) < (y%10); } }; using namespace std; int main() { priority_queue<int,std::vector<int>,less_digit> pq; for ( int i = 0; i < 30; ++i ) { pq.push(i); } while ( !pq.empty() ) { cout << pq.top() << ' '; pq.pop(); } cout << endl; } 実行結果はどうなるでしょう。一ケタ目が大きいものが先に現れるなら、 9 19 29 8 18 28 7