//树的结构
Struct BTreeNode{
int data;
BTreeNode* left;
BTreeNode* right;
}
//创建一颗哈夫曼树 根据一个数组和整数
BTreeNode * CreateHuffman(int a[],int n){
BTreeNode **b,*q;
b=new BTreeNode*[n];
int i,j;
for(i=0;idata=a[i];
b->left=b[i]->right=null;
}
for(i=1;idata=b[k1]->data+b[k2]->data;
q->left=b[k1];q->right=b[k2];
b[k]=q;b[k2]=NULL;
}
delete []b;
return q;
}
//根据BT指向的哈夫曼树求出带圈路径
int WeightPathLenght(BTreeBode * BT,int len){
if(BT==NULL) return 0;
else{
if(BT->left==NULL&&BT->right==NULL){
return BT->data*len;
}else{
return WeightPathLenght(BT->left,len+1)+WeightPathLenght(BT->right,len+1);
}
}
}