c++ - I am trying to use built-in priority queue for a user defined structure and priority as one of element.I got errors -


#include <iostream> #include <queue> using namespace std; struct time{ int index; int number;} class comparetime { public: bool operator()(time& t1, time& t2) {    return (t1.number < t2.number); }}; int main() { // code goes here     priority_queue<time, vector<time>, comparetime> pq;     int t,n,k,i,j;     cin >> t;     while(t--)     {         cin>>n>>k;         int a[n][k+1];         for(i=0;i<n;i++)         {             time t;             cin>>a[i];             t.index=i;             t.number=a[i];             pq.push(t);             for(j=1;j<=a[i];j++)             {                 cin>>a[j];             }         }         while (! pq.empty()) {            time t2 = pq.top();            cout<<t2.number<<" "<<t2.index << endl;            pq.pop();         }     } return 0;} 

i getting errors while compiling on gcc -4.9.2 compiler can me out

example input: 2 3 4 3 1 2 3 2 1 3 2 1 2 2 3 3 1 2 3 2 1 3

example output:

3 0 2 1 2 2 3 0 2 1

i newbie of using priority queue , structure priority queue also.i think got intention sample input , output.if can correct mistakes happy.thanks in advance :)


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -