#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
typedef char ElementType;
typedef Position BinTree;
typedef struct TNode *Position;
struct TNode {
ElementType Data;
BinTree Left;
BinTree Right;
};
BinTree CreatBinTree(); // 创建二叉树
void InorderTraversal(BinTree BT);
void PreorderTraversal(BinTree BT); // 前序遍历
void PostorderTraversal(BinTree BT); // 后续遍历
void LevelorderTraversal(BinTree BT);
int GetHeight(BinTree BT); // 求二叉树的高度
int main()
{
BinTree BT = CreatBinTree();
printf("Inorder:"); InorderTraversal(BT); printf("\n");
printf("Preorder:"); PreorderTraversal(BT); printf("\n");
printf("Postorder:"); PostorderTraversal(BT); printf("\n");
printf("Levelorder:"); LevelorderTraversal(BT); printf("\n");
return 0;
}
void InorderTraversal(BinTree BT)
{
if (BT != NULL)
{
PreorderTraversal(BT->Left);
printf(" %c", BT->Data);
PreorderTraversal(BT->Right);
}
}
void PreorderTraversal(BinTree BT)
{
if (BT != NULL)
{
printf(" %c", BT->Data);
PreorderTraversal(BT->Left);
PreorderTraversal(BT->Right);
}
}
void PostorderTraversal(BinTree BT)
{
if (BT != NULL)
{
PostorderTraversal(BT->Left);
PostorderTraversal(BT->Right);
printf(" %c", BT->Data);
}
}