标题:二叉数的储存及先序遍历
取消只看楼主
luo113927
Rank: 1
等 级:新手上路
帖 子:173
专家分:0
注 册:2006-3-15
 问题点数:0 回复次数: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编辑过]

搜索更多相关主题的帖子: 遍历 储存 
2006-04-09 22:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-56405-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.194479 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved