二叉樹的基本操作(C語言實現)

2021-08-31 12:05:01 字數 943 閱讀 5222

#include#include//二叉樹的節點定義

typedef struct treenode

btnode,*pbtnode;

//先序構造二叉樹

void createbtree(pbtnode *root)

}//先序遍歷二叉樹

void preorder(pbtnode root)

//中序遍歷二叉樹

void inorder(pbtnode root)

//後序遍歷二叉樹

void postorder(pbtnode root)

//輸出葉子結點

void displyleaf(pbtnode root)

}//左結點插入

void inseartleftnode(pbtnode root,char ch)

//右結點插入

void inseartrightnode(pbtnode root,char ch)

//銷毀一顆二叉樹

void clear(pbtnode* root)

//刪除左子樹

void deletelefttree(pbtnode root)

//刪除右子樹

void deleterighttree(pbtnode root)

//查詢結點

pbtnode search(pbtnode root,char ch)

}//求二叉樹的高度

int btreeheight(pbtnode root)

//求葉子結點的個數

int countleaf(pbtnode root)

}//求所有結點的個數

int countall(pbtnode root)

//複製二叉樹

pbtnode copybtree(pbtnode root)

C語言實現二叉樹的基本操作

我在前面的部落格中講解了鍊錶 棧和佇列,這些資料結構其實都是線性表,並且給出了詳細的實現。從今天開始,我們將要來學習樹,樹作為一種資料結構我們經常會用到,作為起步和基礎,我們先來實現二叉樹,也就是每個節點有不超過2個子節點的樹。對於樹的操作,最基本的建立 遍歷 求樹高 節點數等。上傳至 1 節點的定...

c語言實現二叉樹的基本操作

hljs lasso include 二叉樹的節點定義 typedef struct treenode btnode,pbtnode 先序構造二叉樹 void createbtree pbtnode root 先序遍歷二叉樹 void preorder pbtnode root 中序遍歷二叉樹 vo...

C語言實現二叉樹的基本操作

如下 include include 二叉樹的節點定義 typedef struct treenode btnode,pbtnode 先序構造二叉樹 int createbitree pbtnode t return1 先序遍歷二叉樹 void preorder pbtnode root 中序遍歷二...