求助:帮我改改一个C程序(二叉树)

作者在 2006-10-28 07:39:00 发布以下内容

/*-------------------------------------------------
  ------二叉树的链表先序建立与中序输出(C程序)------
  -------------------------------------------------*/

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

typedef struct Node    /*二叉树的链表结构声明*/    
{
 char data;
 struct Node *LChild;
 struct Node *RChild;
}BiTNode, *BiTree;

/*利用“扩展先序遍历序列”创建二叉链表*/
void CreateBiTree(BiTree *bt)
{
 char ch;
 ch=getchar();
 if(ch=='#')   *bt=NULL;
 else
 {
  *bt=(BiTree)malloc(sizeof(BiTNode));
  (*bt)->data=ch;
  CreateBiTree(&((*bt)->LChild));
  CreateBiTree(&((*bt)->RChild));
 }
}

/*中序输出二叉树的结点*/
void InOrder(BiTree root)
{
 if(root!=NULL)
 {
  InOrder(root->LChild);
  printf("%c",root->data);
  InOrder(root->RChild);
 }
}

/*主程序*/
main()
{
 BiTree tree;
 printf("Please input the node of tree:\n");
 CreateBiTree(&tree);
 printf("\nInorder:");
 InOrder(tree);
}

 

程序如上,我的作业来的,等着交,各位,有劳了。

在tc for windows 上运行了,不知怎么的不能创建树,这个有问题,我查不出来。

C | 阅读 2592 次
文章评论,共1条
Firedy(作者)
2006-11-07 07:01
1
由于时间问题,这个程序成功运行后没来的及上来修改,不过一想还是留给大家思考的空间好。因为这个程序只有一个问题,但有几个方法可以修改运行成功,答案不是唯一的。
游客请输入验证码
浏览95108次