二叉树的序遍历
来源:互联网 发布:天策成男捏脸数据 编辑:程序博客网 时间:2024/06/03 15:03
http://wikioi.com/problem/3143/
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<bitset>#include<iomanip>using namespace std;int a[ 20 ][ 3 ] ;void work1(int x)/////////////////////////////////////////////先序遍历{printf("%d ",x);if (a[x][1]!=0) work1(a[x][1]);if (a[x][2]!=0) work1(a[x][2]);}void work2(int x) /////////////////////////////////////////////中序遍历 {if (a[x][1]!=0)work2(a[x][1]);printf("%d ",x);if (a[x][2]!=0) work2(a[x][2]);}void work3(int x)/////////////////////////////////////////////后续遍历{if (a[x][1]!=0) work3(a[x][1]);if (a[x][2]!=0) work3(a[x][2]);printf("%d ",x);}int main(){int n ;while( scanf( "%d" , &n ) != EOF ){for( int i = 1 ; i <= n ; ++i ) scanf( "%d%d" ,&a[ i ][ 1 ] , &a[ i ][ 2 ] ) ; work1( 1 ) ;cout << endl ;work2( 1 ) ;cout << endl ;work3( 1 ) ; cout << endl ;}return 0 ;}
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的序遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- hadoop问题集合
- 你吃过MS SQL 中的User表的亏吗?
- ios图片裁剪
- hdu 3543 Roba number
- 文件过滤驱动操作请求、结果
- 二叉树的序遍历
- 精通软件性能测试与LoadRunner最佳实战 连载八
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定,在C++中CV指const和volatile—1、非成员函数不能有CV限定,2、静态成员函数不能有CV限定
- CF 256C Furlo and Rublo and Game【博弈论,SG函数】
- Mysql性能测试 Mysql性能
- C++文件流ofstream,ifstream
- ios-真机调试出错信息
- Oracle RAC的启动和关闭
- 性能测试工具WAS 性能测试