Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

priority queue using stl in c++

$
0
0

guys i am trying to implement priority queue in c++ using stl . my code is given below :

#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
class compa
{
    public:
    bool compar(const int&a,const int& b)const
    {
       return(a<b);
    }
};
int main()
{
    int i,k;
    priority_queue<int,vector<int>,compa> q;
    for(i=0;i<4;i++)
    {
        cin>>k;
        q.push(k);
    }
    while(!q.empty())
    {
        k=q.top();
        cout<<k<<" ";
        q.pop();
    }
    return 0;
}

i want to implement priority queue to give elements priority in reverse order i.e highest priority to smallest and so on.. please tell me where i am going wrong


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>