#include <bits/stdc++.h>
typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
};
BinTree CreatBinTree(); /* 实现细节忽略 */
int GetHeight( BinTree BT ); //求深度的函数
void InorderTraversal( BinTree BT );//中序遍历函数
void PreorderTraversal( BinTree BT );//前序遍历函数
void PostorderTraversal( BinTree BT );//后序遍历函数
void LevelorderTraversal( BinTree BT );//层序遍历函数
void PreorderPrintLeaves( BinTree BT );//前序输出叶子结点
int main()
{
BinTree BT = CreatBinTree();
printf("%d\n", GetHeight(BT));
printf("Inorder:"); InorderTraversal(BT); printf("\n");
printf("Preorder:"); PreorderTraversal(BT); printf("\n");
printf("Postorder:"); PostorderTraversal(BT); printf("\n");
printf("Levelorder:"); LevelorderTraversal(BT); printf("\n");
printf("Leaf nodes are:");
PreorderPrintLeaves(BT);
printf("\n");
return 0;
}
/* 你的代码将被嵌在这里 */
BinTree CreatBinTree()//前序
PTA 第六章 二叉树的遍历(中序遍历、前序遍历、后序遍历、层序遍历)、求深度、前序输出叶子结点
最新推荐文章于 2023-11-18 20:35:20 发布