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搜索练习的更多相关文章

  1. 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 ...

  2. 2016年12月30日 星期五 --出埃及记 Exodus 21:25

    2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...

  3. 2016年12月29日 星期四 --出埃及记 Exodus 21:24

    2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...

  4. 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,若有 ...

  5. 2016年12月27日 星期二 --出埃及记 Exodus 21:22

    2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...

  6. c++中变量声明和变量定义的区别。2016年12月6日

    整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. mysql学习笔记 第七天

    数据库的备份与还原 数据库的备份与还原是后面章节的内容,但是在学习的时候已经需要数据的备份与还原了,所以就了解了一下.数据库有很多种备份方法,我学习的是其中的一种 备份: 对于数据库的备份: C:&g ...

  2. git 使用笔记(二)

    续 2.15 删除文件 $ rm testDel.txt删除掉工作区的testDel.txt文件, 1)这时可以通过git checkout -- testDel.txt从版本库恢复该文件到工作区 2 ...

  3. (旧)子数涵数·DW——图文混排页面

    一.首先,打开Dreamweaver,新建一个的HTML项目. 二.在设计区里,写一些文字,随便写一点(也可以在代码区中的<body>和</body>之间写). 三.插入一张图 ...

  4. 什么是目标框架别名(What are the Target Framework Monikers (TFMs))?

    我们现在的.NET Core 1.0应用(ASP.NET Core 1.0应用或控制台应用)有了新的被运行在不同框架上的可能性:①运行在.NET Core平台上 ②运行在传统的.NET Framewo ...

  5. RabbitMQ与AMQP协议详解

    1. 消息队列的历史 了解一件事情的来龙去脉,将不会对它感到神秘.让我们来看看消息队列(Message Queue)这项技术的发展历史. Message Queue的需求由来已久,80年代最早在金融交 ...

  6. [Design Pattern] Substitute Interface

    [Design Pattern] Substitute Interface 目的 将对象的成员建立为替身接口的成员,用来解耦对象之间的循环相依. 情景 假设开发人员接手一个系统,在系统里有订单对象.送 ...

  7. [WP8] ListBox的Item宽度自动填满

    [WP8] ListBox的Item宽度自动填满 范例下载 范例程序代码:点此下载 问题情景 开发WP8应用程序的时候,常常会需要使用ListBox作为容器来呈现各种数据集合.但是在ListBox呈现 ...

  8. swift学习笔记之-构造过程

    //构造过程 import UIKit /* 构造过程(Initialization): 1.构造过程是使用类.结构体或枚举类型的一个实例的准备过程.在新实例可用前必须执行这个过程,具体操作包括设置实 ...

  9. jekyll

    bundle show minima查看安装路径 bundle exec github-pages versions 建立一个类似于master的分支,与master是完全独立 git checkou ...

  10. 转:【前端福利】用grunt搭建自动化的web前端开发环境-完整教程

    原文地址:http://blog.csdn.net/wangfupeng1988/article/details/46418203 jQuery在使用grunt,bootstrap在使用grunt,百 ...