数据结构程设计-------哈弗曼编码

#include "iostream" using namespace std; #define MAX 21 typedef struct { char data; int weight; int parent; int left; int right; }huffnode; typedef struct { char cd[MAX]; int start; }huffcode; int main(void) { huffnode ht[2*MAX]; huffcode hcd[MAX], d; int i,k,f,l,r,n,c,m1,m2; cout<<"元素个数: "; cin>>n; for(i=1;i<=n;i++) { cout<<" 第 " << i << " 个元素=>/t节点值: "; cin>>ht[i].data; cout<<" /t/t权 重: "; cin>>ht[i].weight; } for(i=1;i<=2*n-1;i++) ht[i].parent=ht[i].left=ht[i].right=0; for(i=n+1;i<=2*n-1;i++) { m1=m2=32767; l=r=0; for (k=1;k<=i-1;k++) { if (ht[k].parent==0) { if(ht[k].weight

你可能感兴趣的:(数据结构)