#include "stdio.h"
#include "malloc.h"
typedef char TElemType;
typedef struct node
{
TElemType data;
struct node *lchild, *rchild;
}BinTNode;
typedef BinTNode *BinTree;
//按先序建立二叉树
BinTree CreatBinTree()
{
BinTree T; ...#include "stdio.h"
#include "malloc.h"
typedef char TElemType;
typedef struct node
{
TElemType data;
struct node *lchild, *rchild;
}BinTNode;
typedef BinTNode *BinTree;
//按先序建立二叉树
BinTree CreatBinTree()
{
BinTree T; //根节点
TElemType ch; //临时数据
scanf("%c", &ch);
if( ch == ' ' )
T = NULL;
else
{
T = (BinTree)malloc(sizeof(BinTNode)); //申请空间
T->data = ch;
T->lchild = CreatBinTree();
T->rchild = CreatBinTree();
}
return T; //返回根节点
}
//先序访问
void preOrder(BinTree T)
{
if(T);
{
printf( "%3c", T->data );
preOrder( T->lchild );
preOrder( T->rchild );
}
}
void main()
{
BinTree T;
T = CreatBinTree(); //创建二叉树
printf("先序遍历\n");
preOrder( T );
}
请问是哪里的问题?展开 |
|