一、创建三个文件
二、代码实现
1.BinaryTree.c 部分
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <stdbool.h>
#include"BinaryTree.h"
int main()
{
//1.创建二叉树
BTN* node1 = BuyBinaryTreeNode(1);
BTN* node2 = BuyBinaryTreeNode(2);
BTN* node3 = BuyBinaryTreeNode(3);
BTN* node4 = BuyBinaryTreeNode(4);
BTN* node5 = BuyBinaryTreeNode(5);
BTN* node6 = BuyBinaryTreeNode(6);
BTN* node7 = BuyBinaryTreeNode(7);
node1->left = node2;
node1->right = node4;
node2->left = node3;
node2->right = node7;
node4->left = node5;
node4->right = node6;
BTN* tree = node1;
//2.前序遍历
printf("前序遍历:");
BinaryTreePrevOrder(tree);
printf("\n");
//3.中序遍历
printf("中序遍历:");
BinaryTreeMidOrder(tree);
printf("\n");
//4.后序遍历
printf("后序遍历:");
BinaryTreePostOrder(tree);
printf("\n");
//5.二叉树大小
printf("二叉树大小:");
int size = 0;
BinaryTreeSize(tree, &size);
printf("%d\n", size);
//6.二叉树叶子节点数
printf("二叉树叶子节点数:");
int Num = 0;
Num = BinaryTreeLeafNum(tree);
printf("%d\n", Num);
//7.二叉树第k层节点数
printf("二叉树第2层节点数:");
int KLevelNodeNum = 0;
KLevelNodeNum = BinaryTreeKLevelNodeNum(tree,2); //这里选第二层
printf("%d\n", KLevelNodeNum);
//8.二叉树深度
printf("