#include <bits/stdc++.h> using namespace std; class fix_priority_queue { int max_size; priority_queue <int, vector<int>, greater<int> >q; public: fix_priority_queue( int max_size ) { this->max_size = max_size; } void add( int x ) { if ( q.size() < max_size ) { q.push( x ); }else{ int a = q.top(); if ( a < x ) { q.pop(); q.push( x ); } } } void pop() { q.pop(); } int top() { return(q.top() ); } bool empty() { return(q.empty() ); } }; int main() { fix_priority_queue q( 5 ); srand( time( 0 ) ); for ( int i = 0; i != 10; ++i ) { int a = rand(); printf( "%d ", a ); q.add( a ); } printf( "\n" ); while ( !q.empty() ) { printf( "%d ", q.top() ); q.pop(); } return(0); }