考研03 二叉樹遞迴遍歷

2021-09-29 20:52:34 字數 1058 閱讀 8392

1. 先序遍歷

void

preorder

(btnode *p)

}

2. 中序遍歷

void

inorder

(btnode *p)

}

3. 後序遍歷

void

postorder

(btnode *p)

}

4. 求表示式值【後序遍歷】

int

comp

(btnode *p)

else

return p-

>data-

'0';

}else

return0;

}

5. 求二叉樹的深度【後序遍歷】

int

getdepth

(btnode *p)

}

6. 根據前序[1…n],中序[1…n]建立二叉樹

btnode *

preincreate

(int a,

int b,

int l1,

int h1,

int l2,

int h2)

7. 將二叉樹轉換為等價的中綴表示式【中序遍歷】

typedef

struct node

btree;

void

btreetoe

(btree *root)

void

btreetoexp

(btree *root,

int deep)

}

遞迴遍歷二叉樹

include include include 二叉鍊錶表示法 typedef struct tag bitnode bitnode 先序遍歷 void xianxuorder bitnode root 先根 printf c root data 左子樹 xianxuorder root lchil...

二叉樹遞迴遍歷

編寫簡單的程式對下圖二叉樹進行遍歷 先訪問根節點 printf c root ch 再遍歷左子樹 recursion root lchild 再遍歷右子數 recursion root rchild 再遍歷左子樹 recursion root lchild 先訪問根節點 printf c root ...

二叉樹排序 (遞迴遍歷) 遍歷

package week3.day10 2020 8 3 15 08 zmx public class testbinarysorttree class binarysorttree else public void nodeprint class node public boolean addch...