文档介绍:#include<iostream>
using namespace std;
#include<iomanip>
#include<fstream>
#include<cstdlib>
typedef struct Po
else
{
compare[0][1]=j;compare[1][1]=point[j].weight;
}
}
}
length++;
point[compare[0][0]].parent=length;
point[compare[0][1]].parent=length;
point[length].left=compare[0][0];
point[length].right=compare[0][1];
point[length].weight=compare[1][0]+compare[1][1];
}
root=length;
/* cout<<" 序号: 父节点: 左孩子: 右孩子: 比重:"<<endl;
for(i=0;i<=root;i++)
cout<<setw(4)<<i<<setw(8)<<point[i].parent<<setw(8)<<point[i].left<<setw(9)<<point[i].right<<setw(10)<<point[i].weight<<endl;*/
}
void gaincode(int address,char ch[])
{
if(point[address].left||point[address].right)
{
int i=strlen(ch);
char temp1[16];
char temp2[16];
strcpy(temp1,ch);
strcpy(temp2,ch);
temp1[i+1]='\0';
temp1[i]='0';
temp2[i+1]='\0';
temp2[i]='1';
gaincode(point[address].left,temp1);
gaincode(point[address].right,temp2);
}
else
strcpy(code[address],ch);
}
void jiami(char filename[],char fileoutname[]) //对文件进行编码后输出
{
fstream FileIn;
fstream FileOut;
(filename,ios::in);
if(!FileIn)
{cout<<"打开文件失败"<<endl;exit(0);}
(fileoutname,ios::out|ios::binary);
if(!FileOut)
{cout<<"打开文件失败"<<endl;exit(0);}