2016.6.12 codevs搜索练习
1.codevs 3143 二叉树的序遍历
/*只要把输出根节点的位置调换一下就可以了*/
#include<iostream>
using namespace std;
#include<cstdio>
#define N 20
struct node{
int l,r;
}tree[N];
int n;
int rudu[N];
void pre_search(int k)
{
printf("%d ",k);
if(tree[k].l) pre_search(tree[k].l);
if(tree[k].r) pre_search(tree[k].r);
}
void mid_search(int k)
{
if(tree[k].l) mid_search(tree[k].l);
printf("%d ",k);
if(tree[k].r) mid_search(tree[k].r);
}
void tion_search(int k)
{
if(tree[k].l) tion_search(tree[k].l);
if(tree[k].r) tion_search(tree[k].r);
printf("%d ",k);
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;++i)
{
scanf("%d%d",&tree[i].l,&tree[i].r);
rudu[tree[i].l]++;rudu[tree[i].r]++;
}
int i;
for(i=;rudu[i]&&i<=n;++i);
pre_search(i);
printf("\n");
mid_search(i);
printf("\n");
tion_search(i);
return ;
}
2016.6.12 codevs搜索练习的更多相关文章
- 2016年12月31日 星期六 --出埃及记 Exodus 21:26
2016年12月31日 星期六 --出埃及记 Exodus 21:26 "If a man hits a manservant or maidservant in the eye and d ...
- 2016年12月30日 星期五 --出埃及记 Exodus 21:25
2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...
- 2016年12月29日 星期四 --出埃及记 Exodus 21:24
2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...
- 2016年12月28日 星期三 --出埃及记 Exodus 21:23
2016年12月28日 星期三 --出埃及记 Exodus 21:23 But if there is serious injury, you are to take life for life,若有 ...
- 2016年12月27日 星期二 --出埃及记 Exodus 21:22
2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...
- c++中变量声明和变量定义的区别。2016年12月6日
整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...
- 2016年12月26日 星期一 --出埃及记 Exodus 21:21
2016年12月26日 星期一 --出埃及记 Exodus 21:21 but he is not to be punished if the slave gets up after a day or ...
- 2016年12月25日 星期日 --出埃及记 Exodus 21:20
2016年12月25日 星期日 --出埃及记 Exodus 21:20 "If a man beats his male or female slave with a rod and the ...
- 2016年12月24日 星期六 --出埃及记 Exodus 21:19
2016年12月24日 星期六 --出埃及记 Exodus 21:19 the one who struck the blow will not be held responsible if the ...
随机推荐
- 回文串---Best Reward
HDU 3613 Description After an uphill battle, General Li won a great victory. Now the head of state ...
- 回文串--- Girls' research
HDU 3294 Problem Description One day, sailormoon girls are so delighted that they intend to resear ...
- JAVA多用户商城系统源码
最近公司要搞商城,让我多方咨询,最后看了很多,要不就是代码注释不全,要不就是bug多,要么就是文档缺少,最后决定自己开发一套商城. 下面是开发的一些心得体会,权且记录下来,给自己做个记录把. 网址 ...
- 每一个成功的程序员的身后都有一个--------Parse
相信好多同行都用过Parse,而正是因为Parse给我们的开发带来的极大的便利,才有了项目从零开始,到正式上线仅仅用上不到两周的时间,现在Swift还在迅速的发展,很快就会占有大量的市场,现在就就结合 ...
- SQL对字符串数组的处理详解
原文地址:SQL字符串数组操作文章出处:DIY部落(http://www.diybl.com/course/7_databases/sql/sqlServer/2007106/76999.html) ...
- DOJO官方API翻译或解读-dojo/_base/lang --hitch()
hitch() hitch() 是一个函数,会在给定的上下中执行给定一个执行函数.hitch允许你去控制一个函数如何执行,往往在异步操作中起作用. 我们常常会写出这样的代码:(博主:这个代码意图在&q ...
- 实验12:Problem E: 还会用继承吗?
Home Web Board ProblemSet Standing Status Statistics Problem E: 还会用继承吗? Problem E: 还会用继承吗? Time Li ...
- Engine中如何更改矢量图层字段别名?
[解决办法]:使用IClassSchemaEdit.AlterFieldAliasName方法可以更改数据源的别名,如果想在图层的属性中更改显示的别名需要使用ITableFields.FieldInf ...
- 【转】Android Studio中通过快捷键来提取提取方法
今天来给大家介绍一个非常有用的Studio Tips,有些时候我们在一个方法内部写了过多的代码,然后想要把一些代码提取出来再放在一个单独的方法里,通常我们的做法是复制粘贴,现在我来教给大家一个非常简洁 ...
- 【读书笔记】iOS-NSNumber
NSArray和NSDictionary只能存储对象,而不能直接存储任何基本类型的数据,如int,float或struct.但是你可以用对象来封装基本数值.例如,将int型数据封装到一个对象中,然后就 ...