用链表构造哈夫曼树中的一个error

来源:百度知道 编辑:UC知道 时间:2024/06/09 21:01:03
这是我用链表来构造的哈夫曼树的源代码
#include "stdio.h"
#include "stdlib.h"
#include "alloc.h"
#define m 100
struct ptree
{int w;
struct ptree *lchild;
struct ptree *rchild;
};
struct pforest
{struct pforest *link;
struct ptree *root;
};
int WPL=0;
struct ptree *hafm();
void travel();
struct pforest *inforest();
main()
{struct ptree *head ;
int n,i,w[m];
printf("please input weight of every node\n");
for (i=1;i<=n;i++)
scanf("%d",&w[i]);
head=hafm(w,n);
travel(head,0);
printf("The length of the best path is WPL=%d",WPL);
}

void travel(struct ptree *head,int n)
{ struct ptree *p;
p=head;
if(p!=NULL)
{if((p->lchild)==NULL&&(p->rchild)==NULL)
{printf("%d",p->w);
printf("the hops of the node is:%d\n",n);

你的代码是复制的吧?

#include "alloc.h"

改成

#include "malloc.h"
-------------------------------------
#include "stdio.h"
#include "stdlib.h"
#include "alloc.h"
#define m 100
struct ptree
{int w;
struct ptree *lchild;
struct ptree *rchild;
};
struct pforest
{struct pforest *link;
struct ptree *root;
};
int WPL=0;
struct ptree *hafm(); // 这三行
void travel(); //全部删掉
struct pforest *inforest(); //声明与定义不符

Compiling...
ggg.cpp
D:\whb\ceshi\ggg.cpp(33) : error C2660: 'hafm' : function does not take 2 parameters
D:\whb\ceshi\ggg.cpp(34) : error C2660: 'travel' : function does not take 2 parameters
D:\whb\ceshi\ggg.cpp(70) : error C2660: 'inforest' : function does not take 2 parameters
D:\whb\ceshi\ggg.cpp(85) : error