压缩软件:
给定一篇文章,只含有英文大小写字母和空格,统计该文件中各种字符的频率,对各字符进行Huffman编码,将该文件翻译成Huffman编码文件,再将Huffman编 码文件翻译成源文件。
运行结果如下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef struct
{
int value;
int p,l,r;
}HTNode,*HuffTree;
struct fact //因为不是每一篇文章中所有字符都会出现
{ //所以结构体数组存储数组下标真正对应的字符ch以及权值weight
char ch;
int weight;
};
typedef char * * HuffCode; // 字符指针数组用于存储各个字符对应的编码
typedef char * CHAR;
void select(HuffTree &HT,int n,int &s1,int &s2); //查找HT中未被使用的权值最小的