二叉树--链表实现

这篇博客详细介绍了如何使用链表结构实现二叉树的各种操作,包括初始化、创建、遍历(先序、中序、后序、层序)、查找、修改、删除、插入子树等,同时提供了C语言的实现代码。
摘要由CSDN通过智能技术生成
# 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,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值