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

2021-07-24 12:08:59 字數 1491 閱讀 3713

/*   

* 檔名稱:main.cpp,btree.h,btree.cpp

* 完成日期:2023年11月10日

* 版本號:vc++6.0

*

* 問題描述:  實現二叉樹的層次遍歷演算法,並對用」a(b(d,e(h(j,k(l,m(,n))))),c(f,g(,i)))」建立的二叉樹進行測試。

* 輸入描述:a(b(d,e(h(j,k(l,m(,n))))),c(f,g(,i)))

* 程式輸出:對應的二叉樹 序列

*/

// btree.h

#include #include #define maxsize 100

typedef char elemtype;

typedef struct node

tbtnode;

void createtbtnode(tbtnode * &b,char *str);//建立二叉樹

void disptbtnode(tbtnode *b);//輸出二叉樹

void thread(tbtnode *&p);//線索化二叉樹

tbtnode *creathread(tbtnode *b) ; //中序線索化二叉樹

void thinorder(tbtnode *tb);//遍歷線索化二叉樹

#include "btree.h"

#include "stdio.h"

tbtnode *pre; //全域性變數

void createtbtnode(tbtnode * &b,char *str)}}

j++;

ch=str[j];

}}void disptbtnode(tbtnode *b)

}}void thread(tbtnode *&p)

else p->ltag=0;

if (pre->rchild==null) //後繼線索

else pre->rtag=0;

pre=p;

thread(p->rchild); //右子樹線索化

}}tbtnode *creathread(tbtnode *b) //中序線索化二叉樹

return root;

}void thinorder(tbtnode *tb)

p=p->rchild;}}

// main.cpp

#include "btree.h"

#include "stdio.h"

int main()

執行結果:

第十一周專案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...

第十一周專案一(3)

問題描述 執行並重複測試教學內容中涉及的演算法。改變測試資料進行重複測試的意義在於,可以從更多角度體會演算法,以達到逐漸掌握演算法的程度。使用你的測試資料,並展示測試結果,觀察執行結果,以此來領會演算法。輸入描述 若干測試資料。程式輸出 對應資料的輸出。include include define ...