没有合适的资源?快使用搜索试试~ 我知道了~
2huffman编码源程序.txt
需积分: 9 1 下载量 27 浏览量
2020-05-18
00:14:35
上传
评论 1
收藏 4KB TXT 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/txt_preview/12432623/12432623_thumbnail_1.jpg?x-oss-process=style/thumbnail)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
8页
源程序,免费下载。多多关注,点赞哦,新人
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
附1:Huffman编码C源代码
源代码列表:stdafx.h
Huffman.cpp
预编译头文件:stdafx.h 以下代码
#pragma once
#include <iostream>
#include <tchar.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
控制台应用CPP文件:Huffman.cpp
#include "stdafx.h"
typedef struct
{
unsigned long weight;
int parent, lchild, rchild;
} HTNode, *HuffmanTree;
typedef char** HuffmanCode;
HuffmanCode HC;
void Select(HuffmanTree HT, int n, int *s1, int *s2);
void HuffmanCoding(unsigned long *w, int n)
{
int i;
if( n<=1 ) return;
源代码列表:stdafx.h
Huffman.cpp
预编译头文件:stdafx.h 以下代码
#pragma once
#include <iostream>
#include <tchar.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
控制台应用CPP文件:Huffman.cpp
#include "stdafx.h"
typedef struct
{
unsigned long weight;
int parent, lchild, rchild;
} HTNode, *HuffmanTree;
typedef char** HuffmanCode;
HuffmanCode HC;
void Select(HuffmanTree HT, int n, int *s1, int *s2);
void HuffmanCoding(unsigned long *w, int n)
{
int i;
if( n<=1 ) return;
int m = 2*n - 1;
HuffmanTree p;
HuffmanTree HT = (HuffmanTree)malloc((m+1)*sizeof(HTNode));
memset(HT, 0, sizeof(HTNode) * (m+1));
for( p=HT,i=1; i<=n; ++i)
{
++p;
++w;
p->weight = *w;
}
int s1, s2;
for( i=n+1; i<=m; ++i )
{
Select(HT, i-1, &s1, &s2);
HT[s1].parent = i; HT[s2].parent = i;
HT[i].lchild = s1; HT[i].rchild = s2;
HT[i].weight = HT[s1].weight + HT[s2].weight;
}
HC = (HuffmanCode)malloc((n+1)*sizeof(char*));
char *cd = (char*)malloc(n*sizeof(char));
cd[n-1] = 0;
int start;
unsigned long f;
for( i=1; i<=n; ++i )
{
start = n - 1;
int c;
for( c=i, f=HT[i].parent; f!=0; c=f, f=HT[f].parent )
{
HuffmanTree p;
HuffmanTree HT = (HuffmanTree)malloc((m+1)*sizeof(HTNode));
memset(HT, 0, sizeof(HTNode) * (m+1));
for( p=HT,i=1; i<=n; ++i)
{
++p;
++w;
p->weight = *w;
}
int s1, s2;
for( i=n+1; i<=m; ++i )
{
Select(HT, i-1, &s1, &s2);
HT[s1].parent = i; HT[s2].parent = i;
HT[i].lchild = s1; HT[i].rchild = s2;
HT[i].weight = HT[s1].weight + HT[s2].weight;
}
HC = (HuffmanCode)malloc((n+1)*sizeof(char*));
char *cd = (char*)malloc(n*sizeof(char));
cd[n-1] = 0;
int start;
unsigned long f;
for( i=1; i<=n; ++i )
{
start = n - 1;
int c;
for( c=i, f=HT[i].parent; f!=0; c=f, f=HT[f].parent )
{
剩余7页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
*&p小白
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)