求改错,关于哈夫曼树的
构造哈夫曼树出现了这个情况,求解答啊。。。main.obj : error LNK2001: 无法解析的外部符号 "int * a" (?a@@3PAHA)
我main函数里没有这样的符号啊,怎么回事啊。。
#include<iostream>
using namespace std;
#define m 100
struct ptree
{
int w;
struct ptree *lchild;
struct ptree *rchild;
};
struct pforest
{
struct pforest *link;
struct ptree *root;
};
int wpl=0,count=0;
int a[];
struct ptree *hafm(int n,int *w);
void preorder(struct ptree *head);
struct pforest *inforest(struct pforest *f,struct ptree *t);
void main()
{
struct ptree *head;
int n,i,j,w[m];
cout<<"please input the sum of node"<<endl;//提示输入结点数
cin>>n;
cout<<"please input weight of every node"<<endl;//提示输入每个结点的权值
for(i=0;i<=n-1;i++)
cin>>w[i];
head=hafm(n,w);
preorder(head);
for(j=1;j<=count-1;j++)
wpl+=a[count];
cout<<"the length of the best path is WPL="<<wpl<<endl;
}
void preorder(struct ptree *head)
{
if(head!=NULL)
{
cout<<head->w<<" ";
a[count]=head->w;
count++;
preorder(head->lchild);
preorder(head->rchild);
}
}
struct ptree *hafm(int n,int *w)
{
struct pforest *p1,*p2,*f;
struct ptree *ti,*t,*t1,*t2;
int i;
f=(struct pforest *)malloc(sizeof(struct pforest));
f->link=NULL;
for(i=1;i<=n;i++) //产生n棵只有根结点的二叉树
{
ti=(struct ptree *)malloc(sizeof(struct ptree));//开辟新的结点空间
ti->w=w[i-1]; //对结点赋权值
ti->lchild=NULL;
ti->rchild=NULL;
f=inforest(f,ti);
}
while(((f->link)->link)!=NULL)
{
p1=f->link;
p2=p1->link;
f->link=p2->link; //取前两棵树
t1=p1->root;
t2=p2->root;
free(p1); //释放p1
free(p2);
t=(struct ptree *)malloc(sizeof(struct ptree));
t->w=t1->w+t2->w; //权相加
t->lchild=t1;
t->rchild=t2;
f=inforest(f,t);
}
p1=f->link;
t=p1->root;
free(f);
return t;
}
struct pforest *inforest(struct pforest *f,struct ptree *t)
{
struct pforest *p,*q,*r;
struct ptree *ti;
r=(struct pforest *)malloc(sizeof(struct pforest));
r->root=t;
q=f;
p=f->link;
while(p!=NULL)
{
ti=p->root;
if(t->w>ti->w)
{
q=p;
p=p->link;
}
else
p=NULL;
}
r->link=q->link;
q->link=r;
return f;
}