#include#include struct BTNode{ char character; struct BTNode* pLchild; struct BTNode* pRchild; }; struct BTNode* CreatBTree(void); void PreTraverseTree(struct BTNode*);//先序遍历 void InTraverseTree(struct BTNode*);//中序遍历 void PostTraverseTree(struct BTNode*);//后序遍历 int main(void) { struct BTNode* pT=NULL; pT=CreatBTree(); PreTraverseTree(pT); printf("nn"); InTraverseTree(pT); printf("nn"); PostTraverseTree(pT); return 0; } struct BTNode* CreatBTree(void) { struct BTNode* pA=(struct BTNode*)malloc(sizeof(struct BTNode)); struct BTNode* pB=(struct BTNode*)malloc(sizeof(struct BTNode)); struct BTNode* pC=(struct BTNode*)malloc(sizeof(struct BTNode)); struct BTNode* pD=(struct BTNode*)malloc(sizeof(struct BTNode)); struct BTNode* pE=(struct BTNode*)malloc(sizeof(struct BTNode)); pA->character='A'; pB->character='B'; pC->character='C'; pD->character='D'; pE->character='E'; pA->pLchild=pB; pA->pRchild=pC; pB->pLchild=pB->pRchild=NULL; pC->pLchild=pD; pC->pRchild=NULL; pD->pLchild=NULL; pD->pRchild=pE; pE->pRchild=pE->pLchild=NULL; return pA; } void PreTraverseTree(struct BTNode* pT) { if(pT!=NULL) { printf("%cn",pT->character); if(pT->pLchild!=NULL) PreTraverseTree(pT->pLchild); if(pT->pRchild!=NULL) PreTraverseTree(pT->pRchild); } } void InTraverseTree(struct BTNode* pT) { if(pT!=NULL) { if(pT->pLchild!=NULL) InTraverseTree(pT->pLchild); printf("%cn",pT->character); InTraverseTree(pT->pRchild); } } void PostTraverseTree(struct BTNode* pT) { if(pT!=NULL) { if(pT->pLchild!=NULL) PostTraverseTree(pT->pLchild); if(pT->pRchild!=NULL) PostTraverseTree(pT->pRchild); printf("%cn",pT->character); } }



