偶是按例题做的,居然还是不能运行出正确结果,大家帮帮偶
偶实在找不出那有错
#include <stdio.h>
#include <stdlib.h>
#define ok 1
#define error 0
typedef char datatype;
typedef struct Tnode
{
datatype data;
struct Tnode *lchild, *rchild;
}Tnode, *Tree;
int scantree ( Tree T );
int intertree ( Tree *T );
void main()
{
Tree T=NULL;
intertree( &T );
printf("先序遍历的结果是: ");
scantree ( T );
}
int intertree( Tree *T )
{
datatype ch;
scanf("%c",&ch);
if( ch=='/' )(*T)=NULL;
else
{
(*T)=(Tnode *)malloc(sizeof(Tnode));
if(!(*T))
return (0);
(*T)->data=ch;
intertree( &((*T)->lchild) );
intertree( &((*T)->rchild) );
}
return (ok);
}
int scantree( Tree T )
{
if( T )
{
printf("%c",T->data);
if( scantree( T->lchild ) )
if( scantree( T->rchild ) )
return(ok);
return(error);
}
else
return(ok);
}