二叉樹演算法 收藏

2021-04-20 08:05:01 字數 860 閱讀 8842

http://dev.csdn.net/develop/article/50/50350.shtm出自

#include

#include

#include

#define elementtype int

//node structure constructor

typedef struct bt binarytreenode,*btroot;

//function declear

inorder(btroot root);

preorder(btroot root);

postorder(btroot root);

//the main function to excute

main()

//inorder function

inorder(btroot root)

//preorder function

preorder(btroot root)

//postorder function

postorder(btroot root)

/*receive the input data and create a node each time!*/

createtree(btroot root,int nodenum) /* preorder */

printf("create rchild for node %d in layer %d (0 for no)?",nodenum,layer);

scanf("%d",&i);

if(i==0) root->rchild=null;

else

return 0;

}

二叉樹演算法

include include include define elementtype int node structure constructor typedef struct bt binarytreenode,btroot function declear inorder btroot root...

二叉樹演算法

二叉樹的遍歷演算法 1.先序遍歷 對每乙個節點將其看作根節點按照根左右的順序進行遍歷。示例 void preordertree node root 先序遍歷二叉樹 return 2.中序遍歷 對每乙個節點將其看作根節點按照左根右的順序進行便利。示例 void inordertree node roo...

二叉樹演算法

include include define maxsize 20 define max 20 int count 0 int count1 0 int depth int du1 0 int du2 0 樹的儲存結構 typedef struct nodebinode,bitree 棧的儲存結構 ...