資料結構上機 二叉樹

2021-08-11 01:46:43 字數 1190 閱讀 4705

#include 

#include

#include

using

namespace

std;

typedef

char telemtype;

typedef

struct binarytreenode node;

typedef node * bintree;

//建立二叉樹,中間節點->左子樹->右子樹

node* createbinarytree() else

return p;

}//先序遍歷

void preorder(node* root)

}//中序遍歷

void inorder(node* root)

}//後序遍歷

void lastorder(node* root)

}//二叉樹的深度

int depthoftree(node* root)

if( root == null )

}//二叉樹葉子節點數

int leafnum(node* root) else

if( (root->left == null) && (root->right == null) ) else

}int main()

/*abc@@de@g@@f@@@

二叉樹建立成功二叉樹深度為:5

二叉樹葉子節點數為:3

前序遍歷結果:

a b c d e g f

中序遍歷結果:

c b e g d f a

後序遍歷結果:

c g e f d b a

press any key to continue*/

#include 

#include

const

int maxn=105;

char pre[maxn],in[maxn];

struct node;

node* create(int prel,int prer,int inl,int inr)

void postorder(node* root)

int main()

return

0;

}

資料結構 二叉樹 反轉二叉樹

include using namespace std define maxsize 1000 struct binary tree node class queue queue queue void queue push binary tree node btn binary tree node ...

《資料結構》 二叉樹

二叉樹 是 n個結點的有限集,它或為空集,或由乙個根結點及兩棵互不相交的 分別稱為該根的左子樹和右子樹的二叉樹組成。二叉樹不是樹的特殊情況,這是兩種不同的資料結構 它與無序樹和度為 2的有序樹不同。二叉樹的性質 1 二叉樹第 i層上的結點數最多為 2 i 1 2 深度為 k的二叉樹至多有 2 k 1...

資料結構 二叉樹

1.二叉樹 二叉樹是一種特殊結構的樹,每個節點中最多有兩個子節點,如圖1所示 圖1 二叉樹 在圖1中的二叉樹裡,a c有兩個子節點,b d有乙個子節點。對於二叉樹還有圖2中的以下情況 圖2 二叉樹的特殊情況 在博文中還介紹了滿二叉樹和完全二叉樹還有其他的特殊二叉樹。2.二叉樹的實現 有兩種實現方式,...