typedef enum _STATUS {ERROR, OK} STATUS;
typedef struct _BiTNode {
char data;
struct _BiTNode *lchild;
struct _BiTNode *rchild;
} BiTNode, *BiTree;
/*创建二叉树*/
STATUS CreateBiTree(BiTree *T)
{/*按先序次序输入二叉树节点的值,空格表示空树。*/
char ch;
scanf("%c", &ch);
if (ch == ' ') {
*T = NULL;
} else {
if ( !(*T = (BiTNode *)malloc(sizeof(BiTNode)))) exit(-1);
(*T)->data = ch; //生成根节点
CreateBiTree(&((*T)->lchild)); //构造左子树
CreateBiTree(&((*T)->rchild)); //构造右子树
}
return OK;
}
/*中序遍历二叉树*/
STATUS InOrderTraverse(BiTree *T)
{
if (*T) {
if (InOrderTraverse(&((*T)->lchild)))
printf("%c ", (*T)->data);
if (InOrderTraverse(&((*T)->rchild)))
return OK;
return ERROR;
} else {
return OK;
}
}