二叉树编程模型
来源:互联网 发布:淘宝店铺提前什么意思 编辑:程序博客网 时间:2024/06/06 05:26
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _bitree
{
char data;
struct _bitree *lchild,*rchild;
}*BiTree,BiTNode;
BiTree bitree_create(BiTree tree);
void prev_display(BiTree tree);
void midl_display(BiTree tree);
void last_display(BiTree tree);
//建立二叉树
BiTree bitree_create(BiTree tree)
{
char ch = getchar();
if(ch == '#')
tree = NULL;
else
{
tree = (BiTNode *)malloc(sizeof(BiTNode));
if(tree == NULL )
{
printf("creat error!\n");
return;
}
tree->data = ch;
tree->lchild = bitree_create(tree->lchild);
tree->rchild = bitree_create(tree->rchild);
}
return tree;
}
//先序遍历
//中,左,右
void prev_display(BiTree tree)
{
if(tree != NULL)
{
printf("%c ",tree->data);
prev_display(tree->lchild);
prev_display(tree->rchild);
}
}
//中序遍历
//左,中,右
void midl_display(BiTree tree)
{
if(tree != NULL)
{
prev_display(tree->lchild);
printf("%c ",tree->data);
prev_display(tree->rchild);
}
}
//后序遍历
//左,右,中
void last_display(BiTree tree)
{
if(tree != NULL)
{
prev_display(tree->lchild);
prev_display(tree->rchild);
printf("%c ",tree->data);
}
}
//求深度
int main()
{
BiTree tree = bitree_create(tree);
prev_display(tree);
printf("\n");
midl_display(tree);
printf("\n");
last_display(tree);
printf("\n");
return 0;
}
- 二叉树编程模型
- 二叉树的编程模型2
- 二叉树期权定价模型
- 二叉树有关编程
- 二叉树编程实践
- 【编程】二叉树问题
- 【番外篇】利率二叉树模型对冲
- 金融二叉树模型-给期权定价
- 构造二叉树编程小结
- 自主编程实现二叉树
- 编程模型
- 编程练习-二叉树(求二叉树的高度)
- AVL平衡二叉树打印树模型测试
- 采用路径模型实现遍历二叉树的方法
- java二叉树创建的第二种模型
- 线索二叉树模型的建立与遍历
- 采用路径模型实现遍历二叉树的方法
- 编程之美3.9 重建二叉树
- 线性表(二)——单链表(3)——单链表应用举例(3)—— 增序排列节点
- 学习AJAX的各种方法
- java基础
- iOS--网络请求
- 这些棘手的面试问题该如何回答?
- 二叉树编程模型
- OS Diary Day 2 printfmt.c &&printf.c
- linux中head、tail命令的实现
- 猜数字题(Problem ID:1172)
- ARM指令集
- 【读书笔记】iOS网络-底层网络
- webrtc doubango linphone
- 导出excel那些事
- 玩转树莓派之环境搭建—安装TFT屏