#include #include #include using namespace std; struct pr_q //this is a max-priority-queue { //definitions and macros: #define type int //change this to get max-priority-queue for other type #define parent(x) ((x>>1)) #define left(x) ((x<<1)) #define right(x) (((x<<1)+1)) #define heap_size ((heap.size()-1)) pr_q()// initializer { heap.push_back(-1); //to make it 1-based } private: vector heap; void max_heapify(int index) { int maxindex=index; if(left(index)<=heap_size and heap[left(index)]>heap[maxindex]) maxindex=left(index); if(right(index)<=heap_size and heap[right(index)]>heap[maxindex]) maxindex=right(index); if(maxindex==index) return; swap(heap[maxindex],heap[index]); max_heapify(maxindex); } public: bool empty() //whether the queue is empty { return (heap_size<=0); } type top() //returns the maximum element { if(heap_size==0) { cerr<<"Heap underflow"<key) return; heap[index]=key; while(index>1 and heap[index]>heap[parent(index)]) { swap(heap[index],heap[parent(index)]); index=parent(index); } } public: void push(type add)//same as max-heap-insert in CLRS { heap.push_back(add); increase_key(heap_size,add); } //end of definitions: #undef type #undef heap_size #undef parent #undef left #undef right };//end of pr_q int main() { //sort using a priority-queue pr_q queue; int x; while(cin>>x) queue.push(x); while(!queue.empty()) cout<