codevs 3143 二叉树的序遍历
来源:互联网 发布:广西驰程网络办公系统 编辑:程序博客网 时间:2024/06/07 18:28
地址:http://codevs.cn/problem/3143/
题目规定了树的每个位置的编号,所以可以直接用这个编号来遍历。
#include <iostream>using namespace std;int tree[200][2];void preorder(int i) {if(tree[i][0] != 0) {cout << tree[i][0] << " ";preorder(tree[i][0]);}if(tree[i][1] != 0) {cout << tree[i][1] << " ";preorder(tree[i][1]);}}void inorder(int i) {if(tree[i][0] != 0) {inorder(tree[i][0]);}cout << i << " ";if(tree[i][1] != 0) {inorder(tree[i][1]);}}void postorder(int i) {if(tree[i][0] != 0) {postorder(tree[i][0]);cout << tree[i][0] << " ";}if(tree[i][1] != 0) {postorder(tree[i][1]);cout << tree[i][1] << " ";}}int main() {int n;cin >> n;tree[0][0] = 1;for(int i = 1; i <= n; i++) {cin >> tree[i][0] >> tree[i][1];}preorder(0);cout << endl;inorder(1);cout << endl;postorder(0);return 0;}
0 0
- CODEVS 3143 二叉树的序遍历
- codevs 3143 二叉树的序遍历
- codeVS 3143 二叉树的序遍历
- Codevs 二叉树遍历问题 合集
- codevs 3143 二叉树
- wikioi 3143 二叉树的序遍历
- 3143 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- codevs 2471 表达式的转换--二叉树
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- HuffMan编码--文件压缩
- 安卓集训营第四天---JAVA基础数组和排序,枚举,内部类
- URLEncoder和URLDecoder实现转码和解码
- 北斗得与失(1-二次编码的缺点)
- Linux -- bash
- codevs 3143 二叉树的序遍历
- light oj贪心
- 新闻客户端功能类集合
- Uva540 队列与map
- 2015-2016ACM-ICPC NEER northern-subregional-contest E Easy Arithmetic 思维、模拟
- 内部类的详解
- Anroid优化(二)_内存优化
- 简陋自写intList--双色球实例
- linux学习之硬盘的存储原理和内部架构