#包含" stdlib.h "
#包含“conio.h”
#ifndef NULL
#定義NULL 0
#endif
typedef結構節點
{
字符值;
結構節點*pL,* pR
}節點,* pNode
pNode pH
void DeleteBinaryTree(pNode pNode)
{
if ( pNode == NULL)
返回;
if(pNode-& gt;pL!=空)
DeleteBinaryTree(pNode-& gt;pL);
if(pNode-& gt;公關!=空)
DeleteBinaryTree(pNode-& gt;pR);
免費(pNode);
}
void CreateBinaryTree(pNode * PP head)
{
char ch
if ( NULL!= *ppHead)
DeleteBinaryTree(* PP head);
ch = getch();
putch(ch);
if ( ch == ' ')
{
* ppHead = NULL
返回;
}
* PP head =(pNode)malloc(sizeof(node));
(* ppHead)-& gt;value = ch
(* ppHead)-& gt;pL = NULL
(* ppHead)-& gt;pR = NULL
CreateBinaryTree(& amp;(* ppHead)-& gt;pL);
CreateBinaryTree(& amp;(* ppHead)-& gt;pR);
返回;
}
void VisitBinaryTree ( pNode pHead,void (*VisitNode)(char),int order)
{
if ( pHead == NULL)
返回;
if ( order == 1)
(* visit node)(pHead-& gt;值);
visit binary tree(pHead-& gt;pL,VisitNode,order);
if ( order == 2)
(* visit node)(pHead-& gt;值);
visit binary tree(pHead-& gt;pR,VisitNode,order);
if ( order == 3)
(* visit node)(pHead-& gt;值);
}
作廢打印(char ch)
{
printf ( "%c ",ch);
}
void main()
{
printf("請輸入:\ n ");
CreateBinaryTree(& amp;pH);
printf(" \ n \ n結果:\ n ");
VisitBinaryTree ( pH,Print,1);
putch(' \ n ');
VisitBinaryTree ( pH,Print,2);
putch(' \ n ');
VisitBinaryTree ( pH,Print,3);
putch(' \ n ');
DeleteBinaryTree(pH);
}