先序创建二叉树
来源:互联网 发布:淘宝图片视频在线制作 编辑:程序博客网 时间:2024/05/21 13:54
已知二叉树如下图,空节点用*表示,输入时则输入0代替。
input:1 2 0 4 0 0 3 0 5 0 0
1 2 3 * 4 * 5 * * * *
#include<stdio.h>#include<stdlib.h>typedef struct BTNode{ struct BTNode *lchild,*rchild; int data;}BTNode,*btnode;void createBtree(btnode &T){ int t; scanf("%d",&t); if(t==0) T=NULL; else { T=(btnode)malloc(sizeof(BTNode)); T->data=t; createBtree(T->lchild); createBtree(T->rchild); }}void preOrder(btnode T){ if(T) { printf("%d ",T->data); preOrder(T->lchild); preOrder(T->rchild); }}void inOrder(btnode T){ if(T) { inOrder(T->lchild); printf("%d ",T->data); inOrder(T->rchild); }}void postOrder(btnode T){ if(T) { postOrder(T->lchild); postOrder(T->rchild); printf("%d ",T->data); }}int main(){ btnode T=NULL; createBtree(T); printf("output preorder: "); preOrder(T); printf("\n"); printf("output inorder: "); inOrder(T); printf("\n"); printf("output postorder: "); postOrder(T); printf("\n"); return 0;}
0 0
- 先序创建二叉树
- 递归创建先序序列二叉树
- 创建二叉树,并先序遍历
- java先序递归创建二叉树
- java 二叉树/创建/先序/中序/后序
- 先序遍历和中序遍历创建二叉树
- 先序遍历/后序遍历创建线索二叉树
- 已知先序序列、中序序列创建二叉树
- 数据结构复习(先序创建链表二叉树)
- 二叉树的先序创建和遍历
- #法(先序遍历)创建二叉树
- 【数据结构】扩充先序遍历创建二叉树
- 先序创建二叉树及三种遍历
- 二叉树的先序递归创建和遍历
- 二叉树的创建和先序遍历
- 判断平衡二叉树,创建二叉树,先序遍历二叉树
- 二叉树(先序创建,递归先序,中序,后序遍历)-----1
- 二叉树(先序创建,非递归先序,中序遍历)-----2
- epoll详解
- android 读取WEBSERVICE 中的令一种方式
- 数据结构---栈(C++)
- iOS Apple Development Document 详解
- 【windows多线程】多线程笔试面试题汇总
- 先序创建二叉树
- 简单的GitHub for Windows使用方法
- 怎样选择公司
- C 语言的值传递和地址传递
- 【Android开发】找乐,一个笑话App的制作过程记录
- UI控件--TextView
- 分享一个转义emjoy表情的方法
- viewWithTag 获取的文档
- java.net.URLEncode编码 与 URLDecode解码问题