第十一周專案1 驗證演算法(4)

2021-07-08 16:38:33 字數 1157 閱讀 3275

檔名稱:idea.cpp

完成日期:2023年12月07日

#include #include #define n 50        //葉子結點數

#define m 2*n-1 //樹中結點總數

//哈夫曼樹的節點結構型別

typedef struct

htnode;

//每個節點哈夫曼編碼的結構型別

typedef struct

hcode;

//構造哈夫曼樹

void createht(htnode ht,int n)

else if (ht[k].weight

}ht[i].weight=ht[lnode].weight+ht[rnode].weight;

ht[i].lchild=lnode;

ht[i].rchild=rnode;

ht[lnode].parent=i;

ht[rnode].parent=i;

}}//實現哈夫曼編碼

void createhcode(htnode ht,hcode hcd,int n)

hc.start++; //start指向哈夫曼編碼最開始字元

hcd[i]=hc;

}}//輸出哈夫曼編碼

void disphcode(htnode ht,hcode hcd,int n)

m+=ht[i].weight;

sum+=ht[i].weight*j;

printf("\n");

}printf("\n 平均長度=%g\n",1.0*sum/m);

第十一周專案1 驗證演算法(4)

程式 檔名稱 1.cpp 完成日期 2016年11月10日 版本號 vc6.0 問題描述 哈夫曼編碼的演算法驗證 輸入描述 無 程式輸出 測試結果 include include define n 50 葉子結點數 define m 2 n 1 樹中結點總數 哈夫曼樹的節點結構型別 typedef ...

第十一周專案1驗證演算法

define maxsize 100 typedef char elemtype typedef struct node btnode void createbtnode btnode b,char str 由str串建立二叉鏈 btnode findnode btnode b,elemtype x...

第十一周專案1 驗證演算法

問題及 檔名稱 1.cpp 完成日期 2016年11月10日 版本號 v1.0 問題描述 實現二叉樹的層次遍歷演算法,並使用不同測試資料建立二叉樹,進行測試。請利用二叉樹演算法庫。輸入描述 二叉樹字串str 程式輸出 測試結果 btree.h define maxsize 100 typedef c...