- 1
- 0
- 约6.79千字
- 约 8页
- 2019-09-27 发布于江苏
- 举报
二叉树的四种遍历方法和两种求深度的方法
用到了以前学的栈和队列的知识,也算是一种复习。不过用到栈来求深度的时候,改变了二叉树,不知道如何去避免?
// 二叉树.cpp : 定义控制台应用程序的入口点。
#include stdafx.h
#include stdio.h
#include stdlib.h
typedef struct BiTNode{ //二叉树结构
int data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;
#define STACK_INIT_SIZE 100
#define STACKINGMENT 10
int CreateBiTree( BiTNode **T ) //用先序顺序建立二叉树
{
char c;
if( (c = getchar()) == #)
*T = NULL;
else
{
if(!(*T = (BiTree)malloc(sizeof(BiTNode))))
{
printf(ERROR!);
return 0;
}
(*T)-data = c;
CreateBiTree((*T)-lchild);
CreateBiTre
原创力文档

文档评论(0)