具体介绍以及哈夫曼树的构建在书上都有的,也可以看https://blog.csdn.net/xgf415/article/details/52628073了解一下,挺详细的,这里把oj上面题目给出的代码和自己写实现的代码发一下
题目给出代码:
const int maxvalue=100;
const int maxbit=100;
const int maxn=100;
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include<string>
using namespace std;
struct haffnode
{
char ch;
int weight;
int flag;
int parent;
int leftchild;
int rightchild;
};
struct code
{
int bit[maxn];
int start;
int weight;
char ch;
};
void haffman(int weight[],char text[],int n,haffnode hafftree[])
{
int j,m1,m2,x1,x2,i;
for(i=0; i< 2*n-1; i++)
{
if(i < n)
{
hafftree[i].weight