树结构练习——排序二叉树的中序遍历
来源:互联网 发布:好听劲爆的网络dj歌曲 编辑:程序博客网 时间:2024/04/27 20:23
树结构练习——排序二叉树的中序遍历
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description
在树结构中,有一种特殊的二叉树叫做排序二叉树,直观的理解就是——(1).每个节点中包含有一个关键值 (2).任意一个节点的左子树(如果存在的话)的关键值小于该节点的关键值 (3).任意一个节点的右子树(如果存在的话)的关键值大于该节点的关键值。现给定一组数据,请你对这组数据按给定顺序建立一棵排序二叉树,并输出其中序遍历的结果。
Input
输入包含多组数据,每组数据格式如下。
第一行包含一个整数n,为关键值的个数,关键值用整数表示。(n<=1000)
第二行包含n个整数,保证每个整数在int范围之内。
Output
为给定的数据建立排序二叉树,并输出其中序遍历结果,每个输出占一行。
Example Input
1221 20
Example Output
21 20
#include<iostream>using namespace std;int f;typedef struct BiTNode{int data;struct BiTNode *lchild,*rchild;}BiTNode,*BiTree;void visit(BiTree T){if(T->data!=NULL){if(f==1){cout<<" "<<T->data;}else{cout<<T->data;f=1;}}}void insert(BiTree &T,int key){if(T==NULL){T=new BiTNode;T->lchild=T->rchild=NULL;T->data=key;return ;}if(key<T->data)insert(T->lchild,key);elseinsert(T->rchild,key);}void InOrder(BiTree T){if(T){InOrder(T->lchild);visit(T);InOrder(T->rchild);}}int main(){int m,i,n;BiTree T;while(cin>>m){T=NULL;for(i=0;i<m;i++){cin>>n; insert(T,n);}f=0;InOrder(T);cout<<"\n";}return 0;}
0 0
- 树结构练习-排序二叉树的中序遍历
- SDUTOJ 2128 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- SDUT 2128 树结构练习——排序二叉树的中序遍历
- SDUTOJ 2128 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历 SDUT
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历(sdut_2128)
- SDUT 2128 树结构练习——排序二叉树的中序遍历
- Learning Python 028 获取命令行参数
- git#head
- java se 学习笔记
- 【Lecture1】Introduction
- 搭建IPv6环境 测试你的App
- 树结构练习——排序二叉树的中序遍历
- 452. Minimum Number of Arrows to Burst Balloons
- git#branch
- sdut 二叉排序树
- 新书通告
- Step-By-Step Guide To Create Physical Standby On Normal File System For ASM Primary using RMAN (文档 I
- C程序设计_知识回顾
- Creating a physical standby from ASM primary (文档 ID 787793.1)
- sdut 图的深度遍历