当前位置: 代码迷 >> C语言 >> 二叉数的储存及先序遍历
  详细解决方案

二叉数的储存及先序遍历

热度:170   发布时间:2006-04-09 22:57:00.0
二叉数的储存及先序遍历

请大家帮偶看看这程序到底怎么啦!!!!
怎么老出错,大家可以运行一下

#include <stdio.h>
#include <stdlib.h>

typedef char datatype;
typedef struct BiNode
{
datatype data;
struct BiNode *lchild, *rchild;
}BiNode, *BiTree;

int scantree ( BiTree T );
int intertree ( BiTree *T );

void main()
{
BiTree T=NULL;
intertree( &T );
printf("先序遍历的结果是: ");
scantree ( T );
getch();
}

int intertree( BiTree *T )
{
datatype x;
scanf("%c",&x);
if( x=='/' )(*T)=NULL;
else
{
if( !((*T)=( BiNode *)malloc(sizeof(BiNode)) ))
return (0);
(*T)->data=x;
intertree( &((*T)->lchild) );
intertree( &((*T)->rchild) );
}
return (1);
}

int scantree( BiTree T )
{
if( T )
{
printf("%c",T->data);
if( scantree( T->lchild ) )
if( scantree( T->rchild ) )
return(1);
else
return(0);
}
else
return(1);
}

[此贴子已经被作者于2006-4-9 23:36:44编辑过]

搜索更多相关的解决方案: 遍历  储存  

----------------解决方案--------------------------------------------------------
  相关解决方案