结果为:
缺陷:对英文单引号不支持
//构造哈夫曼树和哈夫曼编码的算法实现
//统计下面一段英文的不同字符个数和每个字符的出现频率,利用统计数据构造构造哈夫曼树和哈夫曼编码
#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].wei