# include <stdio.h>
# include <malloc.h>
typedef struct StaticTwoTreeNode
{
char a;
struct StaticTwoTreeNode * lpoint;
struct StaticTwoTreeNode * rpoint;
}StaticTwoTreeNode,* pStaticTwoTreeNode;
pStaticTwoTreeNode CreatList();
void firstOlderTraversal(pStaticTwoTreeNode);
void centerOlderTraversal(pStaticTwoTreeNode);
void afterOlderTraversal(pStaticTwoTreeNode);
int main(void)
{
pStaticTwoTreeNode pT = CreatList();
firstOlderTraversal(pT);
printf("/n");
centerOlderTraversal(pT);
printf("/n");
afterOlderTraversal(pT);
return 0;
}
pStaticTwoTreeNode CreatList(void)
{
pStaticTwoTreeNode pTa = (pStaticTwoTreeNode)malloc(sizeof(StaticTwoTreeNode));
pStaticTwoTreeNode pTb = (pStaticTwoTreeNode)malloc(sizeof(StaticTwoTreeNode));
pStaticTwoTreeNode pTc = (pStaticTwoTreeNode)malloc(sizeof(StaticTwoTreeNode));
pStaticTwoTreeNode pTd = (pStaticTwoTreeNode)malloc(sizeof(StaticTwoTreeNode));
pStaticTwoTreeNode pTe = (pStaticTwoTreeNode)malloc(sizeof(StaticTwoTreeNode));
pTa->a = 'A';
pTa->lpoint = pTb;
pTa->rpoint = pTc;
pTb->a = 'B';
pTb->lpoint = NULL;
pTb->rpoint =NULL;
pTc->a = 'C';
pTc->lpoint = NULL;
pTc->rpoint = pTd;
pTd->a = 'D';
pTd->lpoint = pTe;
pTd->rpoint =NULL;
pTe->a = 'E';
pTe->lpoint = pTe->rpoint = NULL;
return pTa;
}
void firstOlderTraversal(pStaticTwoTreeNode pT)
{
if (pT != NULL)
{
printf("%c", pT->a);
if (pT->lpoint !=NULL)
{
firstOlderTraversal( pT->lpoint);
}
if (pT->rpoint != NULL)
{
firstOlderTraversal( pT->rpoint);
}
}
}
void centerOlderTraversal(pStaticTwoTreeNode pT)
{
if (pT != NULL)
{
if (pT->lpoint !=NULL)
{
centerOlderTraversal( pT->lpoint);
}
printf("%c", pT->a);
if (pT->rpoint != NULL)
{
centerOlderTraversal( pT->rpoint);
}
}
}
void afterOlderTraversal(pStaticTwoTreeNode pT)
{
if (pT != NULL)
{
if (pT->lpoint !=NULL)
{
afterOlderTraversal( pT->lpoint);
}
if (pT->rpoint != NULL)
{
afterOlderTraversal( pT->rpoint);
}
printf("%c", pT->a);
}
}