这是我的多路优先队列实现代码
#include<iostream>
#include<vector>
using namespace std;
template<class T>
class pq
{
int d,n;
vector<int>pq;
vector<int>qp;
const vector<T>&a;
void exch(int i,int j)
{
int t=pq[i];
pq[i]=pq[j];
pq[j]=t;
qp[pq[i]]=i;
qp[pq[j]]=j;
}
void fixup(int k)
{
while(k>1 && a[pq[(k+d-2)/d]]>q[pq[k]])
{
exch(k,(k+d-2)/d);
k=(k+d-2)/d;
}
}
void fixdown(int k,int n)
{
int j;
while((j=d*(k-1)+2)<=n)
{
for(int i=j+1;i<j+d&& i<=n;i++)
if(a[pq[j]]>a[pq[i]])
j=i;
if(!(a[pq[k]]>a[pq[j]]))
break;
exch(k,j);
k=j;
}
}
public:
pq(int n,const vector<T>&a,int d=3):a(a),pq(n+1,0),qp(n+1,0),n(0),d(d){}
int empty() const
{
return n==0;
}
void insert(int v)
{
pq[++n]=v ;
qp[v]=n;
fixup(n);
}
int getmin()
{
exch(1,n);
fixdown(1,n-1);
return pq[--n];
}
void lower(int k)
{
fixup(qp[k]);
}
};
int main()
{
return 0;
}
但它有一些错误,即我做了一些不正确的构造函数,这是我在运行代码时看到的两个错误
1>c:\users\\documents\visual studio 2012\projects\multiway_heap\multiway_heap\multiway_heap.cpp(8): error C2461: 'pq<T>' : constructor syntax missing formal parameters
1> c:\users\\documents\visual studio 2012\projects\multiway_heap\multiway_heap\multiway_heap.cpp(68) : see reference to class template instantiation 'pq<T>' being compiled
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========
所以请帮助我了解错误在哪里