声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
采用二叉链表作为存储结构,完成二叉树的建立,先序、中序和后序遍历的操作,求所有叶子及结点总数的操作等。
#include <stdio.h>
#include <stdlib.h>
//定义24 建立40
//二叉树的链式存储表示
typedef char DataType; //应由用户定义DataType的实际类型
typedef struct node
{ DataType data;
struct node *lchild, *rchild; //左右孩子指针
}BinTNode;
//结点类型
typedef BinTNode *BinTree;//指向结构的指针
void CreateBinTree(BinTree *T); //构造二叉链表
void Preorder(BinTree T); //先序遍历二叉树
void Inorder(BinTree T); //中序遍历二叉树
void Postorder(BinTree T); //后序遍历二叉树
int nodes(BinTree T); //计算总结点数
int leafs(BinTree T); //计算总叶子数
int depth(BinTree T); //计算二叉树的深度
void swap(BinTr