多效第16场 HDU 3999 The order of a Tree(二叉树)
来源:互联网 发布:手机辐射软件下载 编辑:程序博客网 时间:2024/04/30 05:24
没学过二叉树的先序遍历
#include <cstdio>#include <string.h>const int maxn=100050;struct Node{ int l,r,w;}node[maxn];int m; int cnt;void insert (int n,int root){ if(node[root].w<n)//右子树 { if(~node[root].r) { insert(n,node[root].r); } else { node[root].r=cnt; node[cnt++].w=n; } } else { if(~node[root].l) { insert(n,node[root].l); } else { node[root].l=cnt; node[cnt++].w=n; } }}void preorder(int n){ printf(" %d",node[n].w); if(~node[n].l) preorder(node[n].l); if(~node[n].r) preorder(node[n].r);}inline void init (){ memset (node , -1 , sizeof(node)); cnt=0;}int main (){ int w; while (~scanf("%d",&m)) { init(); scanf("%d",&w); node[cnt++].w=w; for (int i=1 ; i<m ; ++i) { scanf("%d",&w); insert (w,0); } printf("%d",node[0].w); if(~node[0].l) preorder(node[0].l); if(~node[0].r) preorder(node[0].r); printf("\n"); } return 0;}
- 多效第16场 HDU 3999 The order of a Tree(二叉树)
- HDU 3999 The order of a Tree 二叉树
- hdu 3999 The order of a Tree(二叉搜索树)
- HDU 3999 The order of a Tree (二叉搜索树+先序遍历)
- HDU 3999 The order of a Tree 二叉搜索树 BST
- 二叉搜索树的前序遍历:hdu 3999 The order of a Tree
- HDU 3999----The order of a Tree(二叉树的前序遍历)
- HDU 3999----The order of a Tree(二叉树的前序遍历)
- hdu 3999The order of a Tree
- Hdu 3999 - The order of a Tree
- HDU 3999 The order of a Tree
- hdu 3999:The order of a Tree
- hdu 3999The order of a Tree
- hdu 3999 The order of a Tree
- hdu 3999 The order of a Tree
- hdu 3999 The order of a Tree
- hdu 3999 The order of a Tree
- HDU 3999 The order of a Tree
- 【专题】关于敏捷测试,我们到底知道多少?
- string和wstring
- (原文)Effective C++条款7:为多态基类声明VIRTUAL析构函数
- APE物理引擎教程
- 对测试的认识
- 多效第16场 HDU 3999 The order of a Tree(二叉树)
- uboot-1.3.2移植到s3c2410
- Android软件开发之发送短信与系统短信库解析(三十)
- ogre学习版本,我个人认为 1.6.5版本比较好
- 浅谈浏览器
- Linux 父子进程终止的先后顺序不同产生不同的后果
- Linux常用命令总结
- 数据查询优化
- (malloc、free)与(new/delete)