Codves 3143 二叉树的序遍历 递归
来源:互联网 发布:javascript写的小游戏 编辑:程序博客网 时间:2024/06/05 19:48
没想到这个题这么水啊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;}
1 0
- Codves 3143 二叉树的序遍历 递归
- 【数据结构与算法】二叉树的遍历(递归遍历、非递归遍历、层序遍历)
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的递归遍历
- 二叉树的遍历(递归)
- 二叉树的先序递归以及非递归遍历
- 关于WAS一点心得
- 【NOI2001】洛谷2024 食物链
- Java 中 MongoDB 使用指南
- HBase Region分裂
- GitHub系列----向GitHub提交代码
- Codves 3143 二叉树的序遍历 递归
- nutch2.3.1源码分析——InjectorJob
- UIImageJPEGRepresentation和UIImagePNGRepresentation
- Android中用文件形式将List数据缓存在本地
- iG/NZT安装使用过程中可能遇到的问题解决办法(根据用户反馈持续更新中...)
- 生成二维码
- 51Nod-1028-大数乘法 V2
- 静态链接ffmpeg库
- Java配置环境变量