数据结构与算法题目集(中文)
6-9 二叉树的遍历 (25分)
本题要求给定二叉树的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 <stdio.h>
#include <stdlib.h>
typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
ElementType Data;
BinTree Left

这篇博客主要介绍了二叉树的遍历问题,包括前序、中序、后序和层次遍历。提供了函数接口定义,并给出了具体的AC代码实现,帮助读者理解和掌握二叉树遍历的算法。
最低0.47元/天 解锁文章
874

被折叠的 条评论
为什么被折叠?



