代码实现:
//哈夫曼编码
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
struct LinkNode
{
char elem;
int count;
int bianma;
char bm[500];
LinkNode* link;
LinkNode* hlink;
LinkNode* rc;
LinkNode* lc;
LinkNode(char e = '#', int c = 1, LinkNode* ptr = NULL, LinkNode* str = NULL, LinkNode* r = NULL, LinkNode* l = NULL) {
elem = e;
count = c;
link = ptr;
hlink = str;
rc = r;
lc = l;
}
};
class List {
public:
void makeempty() {
while (first->link != NULL) {
LinkNode* ptr = first;
first = ptr->link;
delete ptr;
}
}
void gaibian() {
LinkNode* ptr = first->link;
while (ptr != NULL) {
int i = 10;
int count = 1;
int z = ptr->bianma;
while (i <= z) {
count++;
i = i * 10;
}
int q = count - 1;
int j = 0;
while (count != 0) {
int k = 1;
for (int i = 1; i < count; i++) {
k = k * 10;
}
z = z % k;
k = k / 10;
if (z >= k) {
ptr->bm[j] = '1';
}
else {
ptr->bm[j] = '0';
}
j++;
count--;
}
ptr = ptr->link;
}
}
LinkNode* getfirst() {
return first;
}
List() {
first = new LinkNode;