#include <iostream>
using namespace std;
typedef struct BitNode
{
char data;
struct BitNode* leftchild, * rightchild;
}BitNode,*BitTree;
void preOrderTraerver(BitTree T)
{
if (T == NULL)
return;
std::cout << T->data<<"\t";
preOrderTraerver(T->leftchild);
preOrderTraerver(T->rightchild);
}
void inOrderTraerver(BitTree T)
{
if (T == NULL)
return;
inOrderTraerver(T->leftchild);
std::cout << T->data << "\t";
inOrderTraerver(T->rightchild);
}
void PostOrderTraerver(BitTree T)
{
if (T == NULL)
return;
PostOrderTraerver(T->leftchild);
PostOrderTraerver(T->rightchild);
std::cout << T->data << "\t";
}
int main()
{
BitTree T = (BitTree)new BitTree ;
BitTree L = (BitTree)new BitTree;
BitTree R = (BitTree)new BitTree;
L->data = 'B';
L->leftchild = NULL;
L->rightchild = NULL;
R->data = 'C';
R->leftchild = NULL;
R->rightchild = NULL;
T->data = 'A';
T->leftchild=L;
T->rightchild = R;
std::cout << "前序遍历:";
preOrderTraerver(T);
std::cout << std::endl;
std::cout << "中序遍历:";
inOrderTraerver(T);
std::cout << std::endl;
std::cout <<"后序遍历:";
PostOrderTraerver(T);
std::cout << std::endl;
system("pause");
return 0;
}
|