结果为:
缺陷:对英文单引号不支持
//构造哈夫曼树和哈夫曼编码的算法实现
//统计下面一段英文的不同字符个数和每个字符的出现频率,利用统计数据构造构造哈夫曼树和哈夫曼编码
#include <iostream>
#include<string>
#include <map>
using namespace std;
map<char, int> mapData;
map<char, int>::iterator it;
struct HuffManNode {
string data;
int parent{
};
int leftChild{
};
int rightChild{
};
int weight{
};
};
void findTheSmallest(HuffManNode tree[], int range, int &target1, int &target2) {
//找一个没有双亲的结点赋值给target1
for (int i = 1; i <= range; ++i) {
if (tree[i].parent == 0) {
target1 = i;
break;
}
}
for (int i = 1; i <= range; ++i) {
if (tree[i].parent != 0) {
continue;
} else if (tree[i].weight < tree[target1].weight) {

该博客介绍了如何使用哈弗曼树对输入的字符串进行编码,但指出该方法存在不支持英文单引号的缺陷。
最低0.47元/天 解锁文章
5213

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



