C++构造哈夫曼树,运行时只能输入一个节点的初值,怎么回事,求指点

如题,C++构造哈夫曼树,运行时只能输入一个节点的初值,然后就是 process exited with return value 3221225477,怎么回事,求指点。
代码如下:
#include
#define Maxval 10000
using namespace std;
typedef char Datatype;
typedef struct
{
Datatype data;
float weight;
int lchild,rchild,parent;
}HufmanTree;

void ConstHufmanTree(HufmanTree HTree[],int n)
{
int p1,p2,i,j;
float small1,small2;
for(i=0;i<=2*n-1;i++)
{
HTree[i].weight=0.0;
HTree[i].data='0';
HTree[i].parent=0;
HTree[i].lchild=0;
HTree[i].rchild=0;
}//对所有2*n-1个节点进行赋初值;
for(i=0;i {
cin>>HTree[i].data;
cin>>HTree[i].weight;
} //对前n个节点的data和权值进行赋值;

for(i=n;i<2*n-1;i++)
{
p1=p2=0;
small1=small2=Maxval;
for(j=0;j<i;j++)
{
if(HTree[j].parent==0)
{
if(HTree[j].weight<small1)
{
small2=small1;
small1=HTree[j].weigh;
p2=p1;
p1=j;
}
else if(HTree[j].weight<small2)
{
small2=HTree[j].weight;
p2=j;
}
}

 }
HTree[p1].parent=i;
HTree[p2].parent=i;
HTree[i].lchild=p1;
HTree[i].rchild=p2;
HTree[i].weight=HTree[p1].weight+HTree[p2].weight;

}
}

int main()
{
int n;
HufmanTree *HTree;
void ConstHufmanTree(HufmanTree HTree[],int n);
cout<<"please input the number of the leaf:"< cin>>n;

HTree=new HufmanTree[2*n-1];

ConstHufmanTree(HTree,n);

return 0;

}

1个回答

单步调试的时候可以输入多个,但最后出现提示 program received signal SIGTRAP,Trace/breakpoint trap,是怎么回事。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐