|
|
发表于 2005-8-20 16:56:47
|
显示全部楼层
Post by ak70
- #include <stdio.h>
- #include <stdlib.h>
- typedef char DataType;
- typedef struct node {
- DataType data;
- struct node *lchild, *rchild;
- } BinTNode;
- typedef BinTNode *BinTree;
- void CreateBinTree (BinTree *T) {
- char ch;
- int i=1;
- ch=getchar();
- if (ch==' ') {
- T=NULL;
- printf ("abc");
- }
- else {
- T=(BinTNode *)malloc(sizeof(BinTNode));
- T->data=ch;
- CreateBinTree (T->lchild)); //1
- CreateBinTree (T->rchild)); //2
- printf ("aaa");
- }
- }
- void main () {
- BinTree root;
- CreateBinTree (&root);
- }
复制代码
这样就应该行了
是因为你下一个字符接受的是回车,按下面的改可以,另外把你的结束标志换成除空格外的另一个字符
#include <stdio.h>
#include <stdlib.h>
typedef char DataType;
typedef struct node
{
DataType data;
struct node *lchild, *rchild;
} BinTNode;
typedef BinTNode *BinTree;
void CreateBinTree (BinTree *T)
{
char ch;
printf("%s\n"," lease enter");
scanf("\n%c",&ch);
if (ch=='#')
{
*T=NULL;
// printf ("abc");
}
else
{
*T=(BinTNode *)malloc(sizeof(BinTNode));
(*T)->data=ch;
CreateBinTree (&((*T)->lchild)); //1
CreateBinTree (&((*T)->rchild)); //2
// printf ("aaa");
}
}
void main ()
{
BinTree root;
CreateBinTree (&root);
}
已经编译运行过了,可以。 |
|