91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

1、從終端讀入要編碼的字符串,對所輸入的字符串進行頻率統(tǒng)計并建立哈夫曼樹。 2、輸出每個字符的編碼。 3、根據(jù)已有的各個字符的編碼,輸入一段正確的電文,然后對輸入的電文進行譯碼。

資源截圖

代碼片段和文件信息

/**************************************************
實驗六?哈夫曼編碼實現(xiàn)

1、 從終端讀入要編碼的字符串,對所輸入的字符串進行頻率統(tǒng)計并建立哈夫曼樹。
2、 輸出每個字符的編碼。
3、 根據(jù)已有的各個字符的編碼,輸入一段正確的電文,然后對輸入的電文進行譯碼。
?
****************************************************/

#include
#include
#include
#define NULL 0
#define StackSize 20
#define TRUE 1
#define FALSE 0

typedef struct{
char chr;
unsigned?int weight;
char *encode;
}Data;
typedef struct{
char c;
unsigned?int w;
unsigned?int parent;
unsigned?int lchild;
unsigned?int rchild;
}HTNode*HuffmanTree;

int GetData(Data**?ppdint*?n){
int i=0;
int m=0;
char c=0;
Data*?pd=NULL;
L: while((c=getchar())!=‘\n‘){
for(i=0;i if(c==pd[i].chr)?
{pd[i].weight++;goto?L;}
}/*for*/
if(i==m){
pd=(Data*)realloc(pd(m+1)*sizeof(Data));
if(!pd)?return?FALSE;
pd[m].chr=c;
pd[m].weight=1;;
pd[m].encode=NULL;
m++;
}/*if*/
}/*while*/
*n=m;
*ppd=pd;
return TRUE;
}

void Select(HuffmanTree?HTint?nint?*s1int?*s2){
int? i=1s=0t=0;
unsigned?int?value=65535;
for(;i<=n;i++)?if(HT[i].w value=65535;
for(i=1;i<=n;i++)?if(HT[i].w *s1=s;*s2=t;
}

int BuildTree(HuffmanTree*?p_HTData*?pdint?n){
int m=0i=0;
int s1=0s2=0;
HuffmanTree?HT;
m=2*n-1;
if(n<=1)?return?FALSE;
HT=(HuffmanTree)malloc((m+1)*sizeof(HTNode));
if(!HT)?return?FALSE;
for(i=1;i<=n;i++)?{HT[i].c=pd[i-1].chr;HT[i].w=pd[i-1].weight;HT[i].parent=0;HT[i].lchild=0;HT[i].rchild=0;};
for(;i<=m;i++)?{HT[i].c=0;HT[i].w=0;HT[i].parent=0;HT[

評論

共有 條評論