# include <stdio.h>
# include <malloc.h>
typedef struct TREE
{
char data;
struct TREE * lchild;
struct TREE * rchild;
}Tree, * ptree;
void init_tree(ptree &root); //初始化二叉树
void creat_tree(ptree &root); //创建二叉树
void pre_order(ptree &root); //先序遍历
void back_order(ptree &root); //后序遍历
void mid_order(ptree &root); //中序遍历
void leve_order(ptree &root); //层序遍历
int depth_tree(ptree &root); //二叉树深度
int leaf_tree(ptree &root); //二叉树节点个数
bool seach_tree(ptree &root,char key); //寻找二叉树中的值
bool destroy_tree(ptree &root); //销毁二叉树
void assign_tree(ptree &root,char ch,char value); //更改二叉树节点的值
void parent_tree(ptree &root,char value); //找双亲结点
void leftchild_tree(ptree &root, char value); //左孩子结点
void leftbrother_tree(ptree &root,char value); //左兄弟结点
void rightchild_tree(ptree &root,char value); //右孩子结点
void rightbrother_tree(ptree &root,char value); //右兄弟结点
void delete_tree(ptree &root,char ch,int bl); //删除结点
void insert_tree(ptree &root1,ptree &root2 ,char ch,int bl); //插入子树
int main (void)
{
ptree root;
init_tree(root);
printf ("请输入二叉树的值,空值以#代替\n");
creat_tree(root);
printf ("前序遍历:\n");
pre_order(root);
printf ("\n");
/* printf ("中序遍历:\n");
mid_order(root);
printf ("\n");
printf ("后序遍历:\n");
back_order(root);
printf ("\n");
printf ("层序遍历:\n");
leve_order(root);
printf ("\n");
printf ("二叉树的深度\n");
printf ("%d\n",depth_tree(root));
printf ("\n");
printf ("输入要查找的元素\n");
char ch;
scanf ("%c",&ch);
if (seach_tree(root,
二叉树--链表实现
最新推荐文章于 2024-07-18 10:06:09 发布
这篇博客详细介绍了如何使用链表结构实现二叉树的各种操作,包括初始化、创建、遍历(先序、中序、后序、层序)、查找、修改、删除、插入子树等,同时提供了C语言的实现代码。
摘要由CSDN通过智能技术生成