HDU-3999 The order of a Tree 树的遍历
来源:互联网 发布:淘宝买快排被查 编辑:程序博客网 时间:2024/05/23 01:57
题目链接
对指针的理解运用还欠加强
#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<math.h>#include<functional>#include<algorithm>#include<vector>#include<queue>using namespace std;const int maxn =100005;const int inf = 1<<30;//0x7f;typedef __int64 LL;int n;struct node{int w;node *lch,*rch;};node *updata( int u,node *root ){if( root == NULL ){root = new node;root->w = u; root->lch = root->rch = NULL;return root;}else if( root->w > u )root->lch = updata( u,root->lch );else if( root->w < u )root->rch = updata( u,root->rch );return root;}void fun( node *root,int flag ){if( flag )printf("%d",root->w);elseprintf(" %d",root->w);if( root->lch != NULL )fun( root->lch,0 );if( root->rch != NULL )fun( root->rch,0 );}int main(){#ifndef ONLINE_JUDGE freopen("data.txt","r",stdin);#endifint u;while( scanf("%d",&n) != EOF ){node *root = NULL;for( int i = 1; i <= n; i ++ ){scanf("%d",&u);root = updata(u,root);}fun( root,1 );puts("");} return 0;}
0 0
- 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 (二叉搜索树+先序遍历)
- 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
- hdu 3999 The order of a Tree
- hdu 3999 The order of a Tree
- HDU 3999 The order of a Tree 二叉树
- VB.NET关于接口
- Construct Binary Tree from Preorder and Inorder Traversal
- 虔诚的学习者 腾讯2013年实习生笔试题
- 拖拉功能与多点触摸
- 汉澳sinox普及,软件业洗牌在即,一个神话
- HDU-3999 The order of a Tree 树的遍历
- CString 到char*:转换要求 reinterpret_cast、C 样式转换或函数样式转换
- android 自定义主题样式
- 腾讯2012年实习生笔试题
- 比微软kinect更强的视频跟踪算法--TLD跟踪算法介绍
- String[] result = set.toArray(new String[0]); new String[0]如何理解?
- storm0.9.0.1升级安装
- 二叉查找树的实现
- CentOS6.3中Trac和Subversion(SVN)的结合(二)