【正文】
eight。 /*結(jié)點(diǎn)的權(quán)值*/int lchild,rchild,parent。 /*左、右孩子及雙親的下標(biāo)*/}htnode。typedef htnode huffmantree[m+1]。 /* huffmantree是結(jié)構(gòu)數(shù)組類(lèi)型,其0號(hào)單元不用,存儲(chǔ)哈夫曼樹(shù) */typedef struct{char ch。 /*存儲(chǔ)字符*/ char code[n+1]。 /*存放編碼位串*/}codenode。typedef codenode huffmancode[n+1]。 /*huffmancode是結(jié)構(gòu)數(shù)組類(lèi)型,其0號(hào)單元不用,存儲(chǔ)哈夫曼編碼*/功能模塊劃分void main() //主函數(shù)void inithuffmantree(huffmantree ht) //初始化哈夫曼樹(shù)函數(shù)inithuffmantree()void inputweight(huffmantree ht) //輸入權(quán)值函數(shù) void selectmin(huffmantree ht, int i, int *p1, int *p2)void createhuffmantree(huffmantree ht) //構(gòu)造huffman樹(shù),ht[m]為其根結(jié)void huffmancodes(huffmantree ht,huffmancode hcd) /*根據(jù)huffman樹(shù)ht求huffman編開(kāi)始設(shè)置字符數(shù)目n輸入權(quán)值若輸入=n,輸入字符 N Y輸出編碼數(shù)結(jié)束 void inithuffmantree(huffmantree ht)void inputweight(huffmantree ht),存放權(quán)值最小和次小序號(hào)void selectmin(huffmantree ht, int i, int *p1, int *p2)void createhuffmantree(huffmantree ht)void huffmancodes(huffmantree ht,huffmancode hcd) 字符:R S T U V W X Y Z頻度:48 51 80 23 8 18 1 16 10字符: A B C D E F G H I J K L M N O P Q頻度:186 64 13 22 32 103 21 15 47 57 1 2 32 20 57 63 15 1