#定義乙個二叉樹結點#
typedef struct nodebintnode;
typedef bintnode* bintree;
/*計算二叉樹深度的演算法*/
/*二叉樹深度為左子樹,或右子樹的最大深度加上1 */
int bintreedepth(bintree bt)
if(depl > depr)
return depl+1;
else
return depr+1;
}
/*用前序遍歷的方法查詢x值所在的結點*/
int found=0; //定義是否查詢到x的標誌位;
bintnode *p; //存放x值的結點位置;
void findbt(bintree bt, datatype x)
else
}
/*求結點所在的層次*/
//注意: lh為二叉樹bt的層數,函式開始呼叫時它的初值為1 ;
//p為需要查詢的結點,h為p結點所在的層數;
int level(bintree bt, bintnode *p, int lh)
return h;
}
二叉樹幾種遍歷演算法
二叉樹的遍歷 include include include using namespace std typedef struct node bintree typedef struct node1 btnode void creatbintree1 bintree root 前序遍歷建立樹,形如 ...
簡單二叉樹
algorithm.cpp 定義控制台應用程式的入口點。include stdafx.h include define d left 0 define d right 1 template struct bnode bnode plnode 左子樹 bnode prnode 右子樹 t pvalue...
二叉樹 排序二叉樹的簡單實現
二叉樹 排序二叉樹 include using namespace std 二叉樹的節點 date 資料 left 指向二叉樹的左子樹 right 指向二叉樹的右子樹 template struct node template class btree public btree root null c...