二叉树c语言实现 bittree.h 和 bittree.h

这篇博客介绍了如何使用C语言来实现二叉树的数据结构,包括bittree.h和bittree.c两个文件的详细内容。文章可能涉及到递归和遍历等操作,并提示读者如果需要查看相关依赖,可以查阅作者的其他博客资源。
摘要由CSDN通过智能技术生成

bittree.h 文件

#ifndef _BIT_TREE_H_
#define _BIT_TREE_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//树的定义是递归定义的,节点下面又拆分为左子树和右子树
//树是由节点组成,除了叶子节点,其他节点又是相对的根节点,
//相对的根节点下有相对的左右子树

//树的遍历的本质就是走一圈,每一个非叶子节点就是相对的根节点,都经过3次
//第一次访问为先序,第二次访问为中序,第三次访问为后序
#ifndef bool
#define bool int
#define true 1
#define false 0
#endif

//数的头首地址就可以用第一个节点的地址表示
typedef struct BitNode
{
    int data;
    struct BitNode *lchild,*rchild;
}BitNode,*BitTree;

#ifdef __cplusplus
extern "C"{
#endif

extern void preOrder(BitNode* root);
extern void midOrder(BitNode* root);
extern void lastOrder(BitNode* root);
extern void countLeafNodes(BitNode* root,int* sum);
extern int getDepth(BitNode* root);
extern BitNode* copyBitTree(BitNode* root);

#ifdef __cplusplus
}
#endif

#endif

bittree.c 文件

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bittree.h"

//树的先序遍历。递归算法。
void preOrder(BitNode* root)
{
    if (root == NULL)
    {
        return;
    }
    //打印根节点的数据
    printf("先序遍历:%d \n",root->data);
    //遍历左子树
    if (root->lchild != 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值