C语言 哈夫曼树创建输出(静态链表)

#include
#include
#include
#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

 

运行结果:

C语言 哈夫曼树创建输出(静态链表)_第1张图片 

 

你可能感兴趣的:(C语言)