二叉樹建立和遍歷

2022-09-05 08:51:16 字數 876 閱讀 3313

二叉樹建立遍歷規則:

1.先序:根-左-右

2.中序:左-根-右

3.後序:左-右-根

二叉樹定義和輔助函式例如以下:

struct node ;  

void visit(int data)

int indata()

先序建立二叉樹:

struct node* createbitree()//先序建立乙個二叉樹  

return t;

}

先序遍歷二叉樹:

void preorder(struct node* root)  

中序建立二叉樹:

struct node* createbitree()//先序建立乙個二叉樹  

return t;

}

中序遍歷二叉樹:

void inorder(struct node* root)  

後序建立二叉樹

struct node* createbitree()//先序建立乙個二叉樹  

return t;

}

後序遍歷二叉樹

void inorder(struct node* root)  

二叉樹建立和遍歷

二叉樹建立遍歷規則 1.先序 根 左 右 2.中序 左 根 右 3.後序 左 右 根 二叉樹定義和輔助函式如下 struct node void visit int data int indata 先序建立二叉樹 struct node createbitree 先序建立乙個二叉樹 return t...

二叉樹建立和遍歷

include include 帶返回值建立二叉樹 最簡單方法 節點資料結構 struct bs node typedef struct bs node tree tree head,p,root 建立二元查詢樹 有返回值的可以不傳參 沒有的話如何傳參 輸入0代表到了某個葉子節點 tree crea...

二叉樹的建立和遍歷

include include define max len 50 define elemtype char define status int define ok 1 define error 0 define overflow 1 typedef struct nodebitreenode,bi...