急!哈夫曼树的构造,select函数在CreatHaffumanTree 函数里引用了之后之后的操作无法继续
以下是代码,printf("AAA")这样的语句是用来看哪里出错的函数。#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef int Status;
typedef struct
{
int weight;
int parent,lchild,rchild;
char name;
}HTNode,*HuffmanTree;
Status Select(HuffmanTree HT,int len,int s1,int s2)//选最小的两个
{
int x1=0,x2=0,i;
int m1=1000;
int m2=1000;
for(i=1;i<=len;i++)
{
if(HT[i].parent==0&&HT[i].weight<m1)//两个最小中的最小
{
m2=m1;
x2=x1;
m1=HT[i].weight;
x1=i;
printf("x1=%d,m1=%d",x1,m1);
}
else if(HT[i].parent==0&&HT[i].weight<m2)//两个最小中的最大
{
m2=HT[i].weight;
x2=i;
printf("x2=%d,m2=%d",x2,m2);
}
printf("\n");
}
s1=x1;
s2=x2;
}
void CreatHuffmanTree(HuffmanTree HT,int n)//建树
{
int m,i,s1,s2;
if(n<=1) return;
m=2*n-1;
HT=new HTNode[m+1];
for(i=1;i<=m;++i)//把输入的结点弄成只有该结点的树
{
HT[i].parent=0;HT[i].lchild=0;HT[i].rchild=0;
}
printf("请输入该字符集:");
for(i=1;i<=n;++i)
cin>>HT[i].name;
for(i=1;i<=n;++i)//输入树对应的结点
{
printf("结点%c对应的权值为:",HT[i].name);
scanf("%d",&HT[i].weight);
}
for(i=n+1;i<=m;++i)
{
Select(HT,i-1,s1,s2);
printf("AAAA");
HT[s1].parent=i;HT[s2].parent=i;
HT[i].lchild=s1;HT[i].rchild=s2;
HT[i].weight=HT[s1].weight+HT[s2].weight;
printf("BBBB");
}
}
int main()
{
HuffmanTree HT;
char ch;
int n,i;
printf("请输入字符集大小:");
scanf("%d",&n);
CreatHuffmanTree(HT,n);
printf("AAAA");
}