#include<iostream>
#include<string>
#include<cstring>
using namespace std;
const int MaxW=9999;
class HuffNode
{
public:
int weight;
char name;
int parent;
int lchild;
int rchild;
};
class HuffMan
{
private:
void MakeTree()
{
int i,s1,s2;
for(i=lnum+1;i<=len;i++)
{
SelectMin(i-1,&s1,&s2);//找出权值最小的两个节点
huffTree[s1].parent=i;//权值最小的两个节点的父节点从n+1开始
huffTree[s2].parent=i;
huffTree[i].lchild=s1;//父节点左右孩子分别是这两个最小的权值的指针值
huffTree[i].rchild=s2;
huffTree[i].weight=huffTree[s1].weight+huffTree[s2].weight;//父节点的权值是这两个最小的节点的权值之和
}
}
void SelectMin(int pos,int *s1,int *s2)//找出最小权值的的两个节点,并把他们的指针值赋给s1,s2
{
int w1,w2,i;
w1=MaxW;w2=MaxW;
*s1=0;*s2=0;
for(i=1;i<=pos;i++)
{
if(huffTree[i].weight<w1 && huffTree[i].parent==0)//w1比w2小,所以出现有比w1小的权值时,s1的指针值赋给s2,w1的权值赋给w2
{ //一定要注意父节点的值为0是条件,是为了排除已经找出的最小权值的节点重新进行排序
*s2&
#include<string>
#include<cstring>
using namespace std;
const int MaxW=9999;
class HuffNode
{
public:
int weight;
char name;
int parent;
int lchild;
int rchild;
};
class HuffMan
{
private:
void MakeTree()
{
int i,s1,s2;
for(i=lnum+1;i<=len;i++)
{
SelectMin(i-1,&s1,&s2);//找出权值最小的两个节点
huffTree[s1].parent=i;//权值最小的两个节点的父节点从n+1开始
huffTree[s2].parent=i;
huffTree[i].lchild=s1;//父节点左右孩子分别是这两个最小的权值的指针值
huffTree[i].rchild=s2;
huffTree[i].weight=huffTree[s1].weight+huffTree[s2].weight;//父节点的权值是这两个最小的节点的权值之和
}
}
void SelectMin(int pos,int *s1,int *s2)//找出最小权值的的两个节点,并把他们的指针值赋给s1,s2
{
int w1,w2,i;
w1=MaxW;w2=MaxW;
*s1=0;*s2=0;
for(i=1;i<=pos;i++)
{
if(huffTree[i].weight<w1 && huffTree[i].parent==0)//w1比w2小,所以出现有比w1小的权值时,s1的指针值赋给s2,w1的权值赋给w2
{ //一定要注意父节点的值为0是条件,是为了排除已经找出的最小权值的节点重新进行排序
*s2&