資料結構課程設計哈夫曼編碼解碼用c語言

時間 2022-02-07 05:43:33

1樓:匿名使用者

#include

#include

#include

#define n 8

#define m 2*n-1

#define max 2000

typedef struct

huffm;

huffm ht[m+1];

typedef struct

ctype;

void huffmtree(huffm ht[m+1]);

void huffmcode(ctype code[n+1]);

void output (ctype code[n+1]);

/* 構造huffmtree的函式*/

void huffmtree(huffm *ht)

for(i=n+1;i<=m;i++)

else if(ht[j].wi

ht[p1].parent = ht[p2].parent =i;

ht[i].lchild =p1;

ht[i].rchild =p2;

ht[i].wi =ht[p1].wi + ht[p2].wi ;

}// printf("\n ok!");

// for(i=1;i<=m;i++)

// // getchar();

return ;

}/* 求huffmtree編碼的函式*/

void huffmcode(ctype code[n+1])

code[i] = md;}}

/*列印編碼函式*/

void output(ctype code[n+1])

printf(" %d",code[i].start);}}

void main()

for(i=1;i<=n;i++)

printf("please input %d char: \n",n);

getchar();

for(i=1;i<=n;i++)

printf("please input %d rate: \n",n);

getchar();

for(i=1;i<=n;i++)

huffmtree(ht);

huffmcode(code);

output(code);

printf("\ncontinue?1-contine,0-exit\n");

scanf("%d",&choice);

if(choice!=1)

break;

}getchar();

return;

}執行過,正確的

2樓:匿名使用者

我可以做,不過是有償的,呵呵

3樓:

抱歉,我剛剛才學到二叉樹,等我學到那裡再告訴你吧。

求乙個<哈夫曼編碼>資料結構課程設計(c語言版)

4樓:匿名使用者

#include

#include

#include

#define m 50

#define max 1000;

typedef struct

htnode,*huffmantree;

typedef char** huffmancode;//動態分配陣列儲存哈夫曼編碼表

huffmantree huffmantree(int n,int weight)//構建哈夫曼樹

for(i=1;i0;j--)

str[j]=str[j-1];

str[n+1]='\0';

for(k=0;k0;k--)

weight[k]=weight[k-1];

weight[0]=0;

huffmancode hc=null;

huffmantree ht;

ht=huffmantree(n,weight);

huffmancoding(n,hc,ht,str);}

5樓:匿名使用者

我幫你測試了,這個可以滿足你的要求!#include#include

#define max 50

struct a

; struct b

; void main()

for(;i<=2*n-1;i++)

ht[i].parent=ht[i].lchild=ht[i].rchild=0;

for(i=n+1;i<=2*n-1;i++)else if(ht[k].parent==0 && ht[k].weight

ht[s1].parent=ht[s2].parent=i;

ht[i].lchild=s1;

ht[i].rchild=s2;

ht[i].weight=ht[s1].weight+ht[s2].weight;

} for(i=1;i<=n;i++)

hcd[i]=d;

} printf("輸出哈夫編碼:");

for(i=1;i<=n;i++)

printf("\n");}

我們有個資料結構的哈夫曼編碼解碼的課程設計,你能幫幫我嗎

有誰可以用c語言做個哈夫曼編碼和解碼的課程設計 帶圖形介面的(我是學資料結構的) 100

資料結構習題,資料結構考題?

希爾排序每一堂的狀態分別為 第一趟 分成三組。結果為 8,2,13,10,12,14第二趟 分成1組。結果為 2,8,10,12,13,14堆排序 純手打的,求給分,圖的話麼 1 10 2 14 8 12 13 14 12 13 8 2 10 2 10 12 13 8 2 14 13 12 10 8...

資料結構 資料的儲存結構, 討論 資料結構 資料的儲存結構?

1.迴圈佇列 與儲存結構有關,即是與計算機在記憶體中實現有關的概念。佇列 本是乙個邏輯概念,但 迴圈佇列 特指在記憶體中依位址順序存放 資料元素 當隊尾越過規定記憶體區域的下界時,調整隊尾指向記憶體區域的上界,繼續進行入隊操作。2.鍊錶 無疑與儲存結構有關。也就是在體現 資料元素 之間關係時增加一或...

約瑟夫環 資料結構,約瑟夫環 資料結構

你看看這個如何 include include typedef struct lnode lnode,linklist next l 構成迴圈鍊錶 else printf n void main 本人感覺你上面的這段 不太好,main 函式 太多了,main 應該只是乙個測試功能,請你參考下面的 用...

資料結構,程式設計,程式設計中資料結構是什麼?

include include typedef struct node node int main q next null printf the list is n q head while q null printf ninsert the position and the elemnt n in...

資料結構的問題,有關資料結構的問題

1全部 include include 單鏈表結點資料型別的定義 typedef int datatype typedef struct node listnode typedef listnode linklist 採用尾插法建立單鏈表 linklist createlistr1 void r n...