#include<stdio.h>
#include<stdlib.h>
#include"myertree.h"
#include<string.h>
//创建
Tree*create_tree()
{
Tree*ptree=(Tree*)malloc(sizeof(Tree));
if(NULL == ptree)
{
puts("malloc Tree struct error");
return ptree;
}
ptree->proot=NULL;
return ptree;
}
//后序销毁二叉树(可以用递归形式)
int destroy_tree(TNode*proot)
{
if(NULL == proot)
{
return -1;
}
else
{
if(NULL == proot->plchild&&NULL == proot->prchild)
{
free(proot);
return 0;
}
else
{
destroy_tree(proot->plchild);
proot->plchild=NULL;
destroy_tree(proot->prchild);
proot->prchild=NULL;
return 0;
}
}
return 0;
}
//给二叉树插入新结点(可以用递归形式)
int insert_node(TNode**pproot,DATA_T newdata)
{
if(NULL == pproot)
{
puts("NULL pointer error");
return -1;
}
TNode*p=(TNode*)malloc(sizeof(TNode));
if(NULL == p)
{
puts("malloc st
二叉树的三种遍历实现
最新推荐文章于 2024-01-25 21:49:27 发布