没有合适的资源?快使用搜索试试~ 我知道了~
哈夫曼编码系统(对英文加密)
需积分: 10 10 下载量 147 浏览量
2017-12-05
12:32:46
上传
评论
收藏 22KB DOCX 举报
温馨提示
试读
17页
这是数据结构中对哈夫曼(最优二叉树)的运用,适合计算机软件专业大二学生学习最优树的数据结构,C/C++哈夫曼编码系统,仅供参考。
资源推荐
资源详情
资源评论
哈夫曼代码编译器
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int es=8;//8 位压缩
const int maxn=256,maxm=1e8;
const char s0[]="00000000";
typedef struct node
{
int weight;
int parent,lchild,rchild;
} HTNode,*HuffmanTree;
HuffmanTree HT=new HTNode[maxn*2];//哈夫曼树;
char *s,*sb,*sl,*sde;//文本字符串;
char filename[maxn];//文件名
LL num_freq[maxn];//文本字符个数统计;
char st[maxn],ts[maxn];//字符-下标,下标-字符匹配数组;
char** HC;//哈夫曼编码;
char* cd;//哈夫曼辅助编码;
int n;//huffmanTree 结点个数;
void file_read()//读入文件文本
{
cout<<"Please input the name of the file to be read: "<<endl;
cin>>filename;//进行加密的原文件;
getchar();
int size;
ifstream in (filename, ios::in|ios::binary|ios::ate);
size = in.tellg();
in.seekg (0, ios::beg);
s = new char [size];
in.read (s, size);
in.close();
s[size]='\0';
}
void file_write(char* &ans)//写入文本文件;
{
cout<<"Choose the finally file to be written: "<<endl;
cin>>filename;
getchar();
ofstream out(filename);
if(!out.is_open())
{
cout<<"error"<<endl;
exit(0);
}
out<<ans;
out.close();
}
int num_sum()//求字符出现频率;
{
memset(num_freq,0,sizeof(num_freq));
for(int i=0; i<strlen(s); i++)
num_freq[s[i]]++;
int num=0;
for(int i=0; i<maxn; i++)
if(num_freq[i])
{
ts[num]=i;//存 每个下标对应的字符;
st[i]=num++;//存 每个字符对应的下标;
}
cout<<"Statistical character frequency is successfully counted."<<endl;
return num;
}
void Select(const int num,int &s1,int &s2)//选择 0-num 的最小权重结点;
{
for(int i=0; i<num; i++)
if(HT[i].parent==-1)
{
s1=i;
break;
}
剩余16页未读,继续阅读
资源评论
qq_37216098
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 流程图转PAD-N-S图和伪码(软件工程).doc
- C#winform excel导入导出
- 毕业论文上传111111111111
- raisin.zip
- 322个地级市-市场分割指数、市场一体化指数+居民消费价格指数(2004-2022年).txt
- 《基于Java实现自定义控件-天气温度折线图 》+源代码+设计资料
- 希尔伯特矩阵来综合演示数值矩阵与符号矩阵的基本操作
- 《基于51单片机和DS18B20的温度检测和报警系统,可设置报警温度上下限,输出温度采用数码管显示 》+源代码+设计资料
- ESP8266WIFI系统工作原理图.schdoc
- C语言《基于STM32的测量温度与压力的数据处理设计 》+源代码+设计资料
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功