二叉树,哈夫曼树典型问题源代码

您所在的位置:网站首页 霍夫曼编码经典例题 二叉树,哈夫曼树典型问题源代码

二叉树,哈夫曼树典型问题源代码

#二叉树,哈夫曼树典型问题源代码| 来源: 网络整理| 查看: 265

#include 

#include 

#include  

#include 

#define MAXSIZE 100 

#define QUEUE_MAXSIZE 50 

typedef char DATA; 

typedef struct//

哈夫曼树

 

 int weight; 

 int parent; 

 int lchild; 

 int rchild;         

        

}HTNode; 

typedef char * HCode;//

哈夫曼编码

 

void SelectNode(HTNode *ht,int n,int *bt1,int *bt2)//

找出两个最小的数

作为子左右节点

 

 

int i; 

 

HTNode *ht1,*ht2,*t; 

 

ht1=ht2=NULL;//

初始化两个结点为空

 

 

for(i=0;iweight>ht2->weight)//

比较结点权重

 

 

 

 

 

 

 

 

 

 

t=ht2;//

使

h2

指向结点权值为次小的结点

 

 

 

 

 

 

ht2=ht1;//

使

h1

指向结点权值为最小的结点

 

 

 

 

 

 

ht1=t; 

 

 

 

 

 

 

 

 

continue;//

继续循环

 

 

 

 

 

 

 

if(ht1 && ht2)//h1

h2

都有效

 

 

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3