2017-12-27 4 views
1

Ich wurde unter Verwendung eines Algorithmus Prioritätswarteschlange zu implementieren. HierWarum ich erhalte vor Vorlage Argumente fehlen ‚(‘ Token während Prioritätswarteschlange mit?

mein Code
#include <iostream> 
#include<bits/stdc++.h> 
using namespace std; 
int first[2]={2,-2}; 
int second[2]={1,-1}; 
vector<pair<pair<int,int>,int>>vec; 
class compare{ 
    public: 
    bool operator()(pair<pair<int,int>,int>a,pair<pair<int,int>,int>b) 
    { 
     return a.second>b.second; 
    } 
}; 
int main() { 
    long long int a,b,c,d; 
    while(cin>>a>>b>>c>>d) 
    { 
     priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 
     map<pair<int,int>,bool>visited; 
     map<pair<int,int>,int>dist; 
     map<pair<int,int>,pair<int,int>> parent; 
     for(int i=1;i<=9;i++) 
     for(int j=1;j<=9;j++) 
     { 
      dist[make_pair(i,j)]=INT_MAX; 
      visited[make_pair(i,j)]=false; 
     } 
     dist[make_pair(a,b)] = 0; 
     visited[make_pair(a,b)] = true; 
     q.push(make_pair(make_pair(a,b),0)); 
     while(!q.empty()) 
     { 
      pair<int,int> node = q.top().first; 
      int distance = q.top().second; 
      q.pop(); 
      //followed by relaxation step 
     } 
    } 
    // your code goes here 
    return 0; 
} 

Das Problem ist, ich erhalte die folgenden Fehler :

rog.cpp: In function ‘int main()’: 
prog.cpp:39:17: error: missing template arguments before ‘(’ token 
    priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 
       ^
prog.cpp:39:41: error: expected primary-expression before ‘,’ token 
    priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 
             ^
prog.cpp:39:73: error: expected primary-expression before ‘,’ token 
    priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 
                     ^
prog.cpp:39:73: error: expected primary-expression before ‘)’ token 
    priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 

ich bin zu verstehen, nicht in der Lage, was genau die Bedeutung des error.It wold ist eine große Hilfe sein, wenn jemand es für mich

+2

Wack ein 'typedef' oder zwei da drin, aus Gründen der Klarheit. – Bathsheba

+1

Sie sollten [Bits/stdC++. H] (https://stackoverflow.com/q/31816095/1782465) in Ihrem Code nicht einschließen. – Angew

+0

Bitte beachten Sie, dass Sie eine akzeptierte Antwort markieren. Vielen Dank. – alhadhrami

Antwort

2

klären konnte. Sie verwenden nicht die richtige Syntax. Statt

priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 

Schreiben sollten Sie

priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare> q; 

Für weitere Informationen schreiben, beziehen sich auf diesen Link: http://en.cppreference.com/w/cpp/container/priority_queue

1

Veränderung dieser:

priority_queue(pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare) q; 

dazu:

priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,compare> q; 

und Sie werden diesen Code kompiliert bekommen.

Dieser Code ist jedoch nicht lesbar. Erwägen Sie die Verwendung eines typedef.

Verwandte Themen