#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define N 30
#define M 2*N-1
typedef struct {
int weight;
int parant;
int Lchild;
int Rchild;
}HTNode,HuffmanTree[M+1];
void Create_HuffmanTree(HuffmanTree ht,int w[],int n);//创建哈夫曼树
void select(HuffmanTree ht,int n,int *s1,int *s2);//在前n个选项中选权值最小,且双亲为0的两个结点
main()
{
int n=5;
HuffmanTree ht;
int w[n]={5,7,3,2,8};
Create_HuffmanTree(ht,w,n);
int i;
printf("HuffmanTree\n");
for(i=0;i<2*n-1;i++)
{
printf("%d %d %d %d %d\n",i,ht[i].weight,ht[i].parant,ht[i].Lchild,ht[i].Rchild);
}
}
void Create_HuffmanTree(HuffmanTree ht,int w[],int n)
{
int i,j,s1,s2;
int m=2*n-1;
for(i=0;i<n;i++)
{
ht[i].weight=w[i];
ht[i].parant=0;
ht[i].Rchild=0;
ht[i].Lchild=0;
}
for(i=n;i<m;i++)
{
ht[i].Lchild=0;
ht[i].parant=0;
ht[i].Rchild=0;
ht[i].weight&