构造哈夫曼树
左0右1
Status InitStack(SqStack *s) {
s.base = (SElemtype*)mallco(MAXSIZE*sizeof(SElemtype));
s.top = s.base;
return OK;
}
void CreatHuffmanCode(HuffmanTree HT,HuffmanCode *HC,int n){
//从叶子到根逆向求每个字符的哈夫曼编码,并存储在编码表HC中;
HC=new char*[n+1];
cd=new char[n];//分配动态零时空间;
cd[n-1]='\0';
for(i=1;i<=n;i++){
start=n-1;
f=HC[i].parent;
while(f!=0){//当结点不为根
start--;
if(i==HC[f].lchild) cd[start]='0';
else cd[start]='1';
}
HC[i]=new char[n-start];//为第i个字符编码分配空间;
strcpy(HC[i],*cd[start]);
}
delete cd;
}