Codves 3143 二叉树的序遍历 递归
2016-10-10 17:29
134 查看
没想到这个题这么水啊QAQ。
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int MAXN = 5000 + 50; int lson[MAXN], rson[MAXN]; void xian(int x) { if(!x) return; printf("%d ", x); xian(lson[x]); xian(rson[x]); } void zhong(int x) { if(!x) return; zhong(lson[x]); printf("%d ", x); zhong(rson[x]); } void hou(int x) { if(!x) return; hou(lson[x]); hou(rson[x]); printf("%d ", x); } int main() { int n; scanf("%d", &n); for(int i = 1; i <= n; i ++) { int l, r; scanf("%d%d", &l, &r); lson[i] = l; rson[i] = r; } xian(1); puts(""); zhong(1); puts(""); hou(1); puts(""); return 0; }
相关文章推荐
- 二叉树非递归遍历
- c语言实现二叉树先序,中序,后序(递归),层次遍历,求叶子节点个数及树的深度,下一篇写非递归的遍历
- 数据结构与算法学习记录--二叉树的创建,递归遍历,非递归遍历的实现
- 二叉树的遍历(递归,非递归)实现
- 二叉树测试,递归遍历,随后加上非递归遍历
- 遍历二叉树-递归和非递归算法
- 二叉树非递归遍历
- iOS:二叉树多级表格的使用,使用三方库TreeTableView-master实现对json解析数据的递归遍历整理成树状结构
- 二叉树前序、中序、后序遍历非递归写法的透彻解析
- 分别用递归和非递归方式实现二叉树的先序、中序和后序遍历
- 二叉树的四种遍历(递归、非递归)
- 非递归实现二叉树的各种遍历
- 二叉树的中序非递归遍历c语言版
- leetcode 94. Binary Tree Inorder Traversal 二叉树中序递归遍历
- 二叉树创建及遍历(递归遍历)
- 非递归遍历二叉树
- 二叉树的递归和非递归遍历
- 详细讲解二叉树三种遍历方式的递归与非递归实现
- 二叉树递归求高度,非递归求高度,层次遍历
- 二叉树概念及递归与非递归遍历