#include <stdio.h>
#include <string.h>
#define TElemType int
int top = -1; // top变量时刻表示栈顶元素所在位置
//初始化队头和队尾指针开始时都为0
int front = 0, rear = 0;
//构造结点的结构体
typedef struct BiTNode {
TElemType data; // 数据域
struct BiTNode* lchild, * rchild; //左右孩子指针
}BiTNode,*BiTree;
// 初始化树的函数
void createBiTree(BiTree *T) {
*T = (BiTNode*)malloc(sizeof(BiTNode));
(*T)->data = 1;
(*T)->lchild = (BiTNode*)malloc(sizeof(BiTNode));
(*T)->rchild = (BiTNode*)malloc(sizeof(BiTNode));
(*T)->lchild->data = 2;
(*T)->lchild->lchild = (BiTNode*)malloc(sizeof(BiTNode));
(*T)->lchild->rchild = (BiTNode*)malloc(sizeof(BiTNode));
(*T)->lchild->rchild->data = 5;
(*T)->lchild->rchild->lchild = NULL;
(*T)->lchild->rchild->rchild = NULL;
(*T)->rchild->data = 3;
(*T)->rchild->lchild = (BiTNode*)malloc(sizeof(BiTNode));
(*T)->rchild->lchild->data = 6;
(*T)->rc
C语言数据结构学习——二叉树遍历法
最新推荐文章于 2024-08-15 16:50:17 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)