帮帮忙,把先序遍历变成递归的先序遍历
#include "stdio.h"#include "stdlib.h"
#define MAXSIZE 215
typedef char TElemType;
typedef int Status;
typedef struct bitree
{
TElemType data;
struct bitree *lchild,*rchild;
}BiTNode, *BiTree;
BiTree Create_Tree()
{
BiTree T;
char a;
scanf("%s",&a);
if(a=='#')
T=NULL;
else
{
T= (BiTNode*) malloc (sizeof(BiTNode));
T->data = a;
printf("输入左孩子的值\n");
T->lchild = Create_Tree();
printf("输入右孩子的值\n");
T->rchild = Create_Tree();
}
return T;
}
void PreOrderTraverse(BiTree T)
{
if(T!=NULL)
{
printf("%c_ ",T->data);
PreOrderTraverse(T->lchild);
PreOrderTraverse(T->rchild);
}
}
Status PrintElement(TElemType e)
{
printf("%c", e);
return 1;
}
void InOrderTraverse(BiTree T)
{
if(T!=NULL)
{
InOrderTraverse(T->lchild);
printf("%c_ ",T->data);
InOrderTraverse(T->rchild);
}
}
void PostOrderTraverse(BiTree T)
{
if(T!=NULL)
{
PostOrderTraverse(T->lchild);
PostOrderTraverse(T->rchild);
printf("%c_ ",T->data);
}
}
void LevelOrder(BiTNode *bt) /*层次遍历二叉树bt*/
{
BiTNode* queue[MAXSIZE];
int front,rear;
if (bt==NULL)
return;
front=0; /*非循环队列*/
rear=0;
queue[rear++]=bt;
while(front!=rear)
{
printf("%c_",queue[front]->data); /*访问队首结点的数据域*/
if (queue[front]->lchild!=NULL) /*将队首结点的左孩子指针入队列*/
{
queue[rear]=queue[front]->lchild;
rear++;
}
if (queue[front]->rchild!=NULL) /*将队首结点的右孩子指针入队列*/
{
queue[rear]=queue[front]->rchild; rear++;
}
front++;
} /* while */
}/* LevelOrder*/
int main()
{
BiTree root;
root=Create_Tree();
printf("\n先序遍历");
PreOrderTraverse(root);
printf("\n中序遍历");
InOrderTraverse(root);
printf("\n后序遍历");
PostOrderTraverse(root);
printf("\n层次遍历");
LevelOrder(root);
printf("\n");
return 0;
}
版主啊,帮我把先序遍历变成递归的先序遍历