树结构练习——排序二叉树的中序遍历
来源:互联网 发布:apache httppost 编辑:程序博客网 时间:2024/06/15 04:50
题目描述
输入
输出
示例输入
1221 20
示例输出
21 20
提示
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
int data;
struct node*l,*r;
};
int mid[1500],k;
struct node*insert(struct node*t,int x)
{
if(t==NULL)
{
t=(struct node*)malloc(sizeof(struct node));
t->data=x;
t->l=NULL;
t->r=NULL;
}
else if(x<t->data)
{
t->l=insert(t->l,x);
}
else
t->r=insert(t->r,x);
return t;
}
struct node*creat(int a[],int n)
{
struct node*t=NULL;
int j=0;
while(j<n)
{
t=insert(t,a[j]);
j++;
}
return t;
}
void inorder(struct node*t)
{
if(t)
{
inorder(t->l);
mid[k++]=t->data;
inorder(t->r);
}
}
int main()
{
int n,i,a[1500];
struct node*t;
while(~scanf("%d",&n))
{ memset(mid,0,sizeof(mid));
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
t=creat(a,n);
k=0;
inorder(t);
for(i=0;i<=k-1;i++)
{
if(i==k-1)
printf("%d",mid[k-1]);
else printf("%d ",mid[i]);
}
printf("\n");
}
return 0;
}
- 树结构练习-排序二叉树的中序遍历
- SDUTOJ 2128 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- SDUT 2128 树结构练习——排序二叉树的中序遍历
- SDUTOJ 2128 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历 SDUT
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历
- 树结构练习——排序二叉树的中序遍历(sdut_2128)
- SDUT 2128 树结构练习——排序二叉树的中序遍历
- apache性能优化
- laravel框架的搜索后分页
- Java获取时间差(天数差,小时差,分钟差)
- (POJ 3494)Largest Submatrix of All 1’s (DP、单调栈)
- cocos斗地主发牌动画
- 树结构练习——排序二叉树的中序遍历
- ZZULI-oj-1913 小火山的计算能力 ( 模拟 )
- sort命令详解高级语法
- HDOJ 1558 Segment set(并查集 + 线段判交)
- hdu 4966 GGS-DDU (最小树形图)
- Scalaz(53)- scalaz-stream: 程序运算器-application scenario
- 隐私策略
- Python
- C#控制台基础 list<int>添加元素并输出实例