哈夫曼树及其编码

哈夫曼树编码 代码
#include
#include
#include
typedef struct{
int weight;
int parent,lchild,rchild;
}HTNode,*HuffmanTree;
typedef char ** HuffmanCode;

void Select(HuffmanTree HT,int n,int &first,int &second)
{
    int min=100000;
    for (int i=0;iHT[i].weight&&HT[i].parent==0){
            first=i;
            min=HT[i].weight;
        }
    }
    min=100000;
    for (int i=0;iHT[i].weight&&first!=i&&HT[i].parent==0){
            second=i;
            min=HT[i].weight;
        }
    }
}
void HuffmanCoding(HuffmanTree &HT,HuffmanCode &HC,int *w,int n)
{
    if(n<1) return;
    int m=2*n-1;
    HT=(HuffmanTree)malloc((m+1)*sizeof(HTNode));
    for (int i=0;i

你可能感兴趣的:(哈夫曼树及其编码)