1、实验内容:
统计下面一段英文的不同字符个数和每个字符的出现频率,利用统计数据构造构造哈夫曼树和哈夫曼编码
The Chinese official said he viewed the Trump Presidency not as an aberration but as the product of a failing political system. This jibes with other accounts. The Chinese leadership believes that the United States, and Western democracies in general, haven’t risen to the challenge of a globalized economy, which necessitates big changes in production patterns, as well as major upgrades in education and public infrastructure. In Trump and Trumpism, the Chinese see an inevitable backlash to this failure.
2、实现代码:
#include <iostream>
#include<cstring>
#include<string.h>
using namespace std;
struct Tag
{
char ch; //字符
int value; //频率
}T[100];
typedef struct
{
int weight;
int parent, lchild, rchild;
}HTNode, *HuffmanTree;
typedef char **HuffmanCode;
bool Judge(char temp, int j)//判断是否重复
{
for (int i = 0; i < j; i++)
if (T[i].ch == temp) return true; //重复
return false;
}
//统计下面一段英文的不同字符个数和每个字符的出现频率
int GetCount(char *str)//写入每种字符及其出现频率
{
int j = 0;
for (int i = 0; i < 1000; i++)
{
char temp= str[i];
if (!Judge(temp, j))
{
T[j].ch = temp;
T[j]

本文介绍了如何统计英文字符频率并利用这些数据构建哈夫曼树和哈夫曼编码。实验内容包括分析一段英文文本,识别不同字符及其出现频率,然后详细阐述了实现这一过程的代码步骤。
最低0.47元/天 解锁文章
3364

被折叠的 条评论
为什么被折叠?



