Problem2004--二叉树的遍历

2004: 二叉树的遍历

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
[Submit] [Status] [Web Board] [Creator:]

Description

本题要求给定二叉树的4种遍历。 函数接口定义: void InorderTraversal( BinTree BT ); void PreorderTraversal( BinTree BT ); void PostorderTraversal( BinTree BT ); void LevelorderTraversal( BinTree BT ); 其中BinTree结构定义如下: typedef struct TNode *Position; typedef Position BinTree; struct TNode{ ElementType Data; BinTree Left; BinTree Right; }; 要求4个函数分别按照访问顺序打印出结点的内容,格式为一个空格跟着一个字符。 裁判测试程序样例: #include #include typedef char ElementType; typedef struct TNode *Position; typedef Position BinTree; struct TNode{ ElementType Data; BinTree Left; BinTree Right; }; BinTree CreatBinTree();

Input

其中BinTree结构定义如下: typedef struct TNode *Position; typedef Position BinTree; struct TNode{ ElementType Data; BinTree Left; BinTree Right; };

Output

要求4个函数分别按照访问顺序打印出结点的内容,格式为一个空格跟着一个字符

Sample Input Copy

图1

Sample Output Copy

Inorder: D B E F A G H C I
Preorder: A B D F E C G H I
Postorder: D E F B H G I C A
Levelorder: A B C D F G I E H

Source/Category

104