题目1201:二叉排序树
来源:互联网 发布:rng淘宝官方旗舰店 编辑:程序博客网 时间:2024/06/18 10:30
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <stack>#include <queue>using namespace std; //exp3.5#include <stdio.h>#include <string.h>struct Node{ Node *lchild; Node *rchild; int c;}Tree[110];int loc;Node *creat(){ Tree[loc].lchild = Tree[loc].rchild = NULL; return &Tree[loc++];} void postOrder(Node *T){ if(T->lchild) postOrder(T->lchild); if(T->rchild) postOrder(T->rchild); printf("%d ",T->c);}void inOrder(Node *T){ if(T->lchild) inOrder(T->lchild); printf("%d ",T->c); if(T->rchild) inOrder(T->rchild);}void preOrder(Node *T){ printf("%d ",T->c); if(T->lchild) preOrder(T->lchild); if(T->rchild) preOrder(T->rchild);}Node *Insert(Node *T,int x){ if(T==NULL){ T = creat(); T->c = x; return T; } else if(x < T->c) T->lchild = Insert(T->lchild,x); else if(x > T->c) T->rchild = Insert(T->rchild,x); return T;}int main(){ int n; while(scanf("%d",&n)!=EOF){ loc = 0; Node *T = NULL; for(int i=0;i<n;i++){ int x; scanf("%d",&x); T = Insert(T,x); } preOrder(T); printf("\n"); inOrder(T); printf("\n"); postOrder(T); printf("\n"); } return 0;} /************************************************************** Problem: 1201 User: cust123 Language: C++ Result: Accepted Time:50 ms Memory:1520 kb****************************************************************/
0 0
- (题目35)题目1201:二叉排序树
- 题目1201:二叉排序树
- 题目1201:二叉排序树
- 题目1201:二叉排序树
- 题目1201:二叉排序树
- 题目1201:二叉排序树
- 题目1201:二叉排序树
- Jobdu 题目1201:二叉排序树
- 题目1201:二叉排序树
- 题目1201:二叉排序树
- 九度题目1201:二叉排序树
- 九度题目1201:二叉排序树
- 九度题目1201:二叉排序树
- 题目1201:二叉排序树 -九度
- 【九度】题目1201:二叉排序树
- 九度oj 题目1201:二叉排序树
- 九度OnlineJudge题目1201:二叉排序树
- 九度OJ题目1201:二叉排序树
- 字符串之间以及与int float double转换
- CSS中隐藏内容的3种方法及属性值
- js字符串补0
- 使用TFS实现ABP项目的持续集成(我靠,截了这么多图片都消失了,CSDN牛掰啊)
- HDU 3068 最长回文
- 题目1201:二叉排序树
- 自己整理的eclipse的快捷键
- strsep的作用
- web worker
- Learning with ensembles
- VS2013创建CUDA文件
- LeetCode 217. Contains Duplicate
- 【java】二叉树重建
- 高精度开方