数据结构:哈夫曼树的应用

2016-02-19 15:54 3 1 收藏

今天给大家分享的是由图老师小编精心为您推荐的数据结构:哈夫曼树的应用,喜欢的朋友可以分享一下,也算是给小编一份支持,大家都不容易啊!

【 tulaoshi.com - 编程语言 】

#includestdio.h
  #includestdlib.h
  #includestring.h
  #includeconio.ha
  #includegraphics.h
  #define MAXVALUE 200           /*权值的最大值*/
  #define MAXB99v  30             /*最大的编码位数*/
  #define MAXNODE 30             /*初始的最大的结点数*/
   strUCt haffnode
           {char data;
     int weight;
                          int flag;
                          int parent;       /*双亲结点的下标*/
                          int leftchild;    /*左孩子下标*/
                          int rightchild;   /*右孩子下标*/
           };
   struct haffcode
           {int bit[MAXNODE];
                          int start;        /*编码的起始下标*/
     char data;
     int weight;       /*字符权值*/
           }; 
  /*函数说明*/
  /************************************************************************/
  void pprintf(struct haffcode haffcode[],int n);
  /*输出函数*/
  void haffmantree(int weight[],int n,struct haffnode hafftree[],char data[]);
  /*建立哈夫曼树*/
  void haffmancode(struct haffnode hafftree[],int n,struct haffcode haffcode[]);
  /*求哈夫曼编码*/
  void test(struct haffcode haffcode[],int n);
  /*测试函数*/
  void end();
  /*结束界面函数*/
  /************************************************************************/ 
  void haffmantree(int weight[],int n,struct haffnode hafftree[],char data[])
      /*建立叶结点个数为n,权值数组为weight[]的哈夫曼树*/
      {int i,j,m1,m2,x1,x2;
       /*哈夫曼树hafftree[]初始化,n个叶结点共有2n-1个结点*/
           for(i=0;i2*n-1;i++)
          {if(in)  {hafftree[i].data=data[i];
       hafftree[i].weight=weight[i];   /*叶结点*/
             }
           else     {hafftree[i].weight=0;           /*非叶结点*/
       hafftree[i].data='

来源:https://www.tulaoshi.com/n/20160219/1610683.html

延伸阅读
我想每个计算机专业的学生或多或少都接触过哈夫曼编码,数据结构中的老问题了。大体就是给出一些字符,和这些字符的出现频率,让你为这些字符设计一个二进制编码,要求频率最高的字符的编码最短。解决的方法是构造一棵哈夫曼树(二叉树),其基本思路是,每次从这些字符中挑出两个频率最低的,然后构造一个新的结点,使新结点的左右孩子指针分别...
  第十五章 Linux核心数据结构 本章列出了Linux实用的主要数据结构。 block_dev_struct 此结构用于向核心登记块设备,它还被buffer cache实用。所有此类结构都位于blk_dev数组中。 struct blk_dev_struct { void (*request_fn)(void); struct request * current_request; struct reque...
3. 把中缀表达式转换为后缀表达式的算法     设以’@’字符作为结束符的中缀算术表达式已经保存在s1字符串中,转换后得到的后缀算术表达式拟存于s2字符串中。由中缀表达式转换为后缀表达式的规则可知:转换前后,表达式中的数值项的次序不变,而运算符的次序发生了变化,由处在两个运算对象的中间变为处在两个运算对象的后面...
标签: ASP
  /*数据结构*/ /*bbs用户表*/ if exists(select * from sysobjects where id = object_id('BBSUser')) drop table BBSUser go create table BBSUser ( id int identity primary key , UserName varchar(20) default '' not null , Password varchar(10) default '' not null , Email varchar(100) default '' not null , Homepage var...
标签: ASP
  /*************************************************************************/ /* */ /* procedure : up_GetForumList */ /* */ /* Description: 取得版面列表 */ /* */ /* Parameters: None */ /* */ /* Use table: forum , bbsuser */ /* */ /* Author: bigeagle@163.net */ /* */ /* Date: 2000/2/10 */ /* */ /* History: */ /* *...

经验教程

149

收藏

57
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部