标题:程序运行不出来,
取消只看楼主
相思豆
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-10-25
结帖率:50%
已结贴  问题点数:11 回复次数:1 
程序运行不出来,
#include"stdio.h"
#include"malloc.h"
typedef  char elemtype;
typedef struct BiTNode
{
elemtype data;
 struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;

int createBiTree(BiTree T) {
   char ch;
   scanf(&ch);
    if (ch=='#') T = NULL;
    else{
   
    T=(struct BiTNode *)malloc(sizeof(struct BiTNode));
   
      T->data = ch;              // Éú³É¸ù½áµã
      createBiTree(T->lchild);   // ¹¹Ôì×ó×ÓÊ÷
      createBiTree(T->rchild);   // ¹¹ÔìÓÒ×ÓÊ÷
    }
return 1;} // CreateBiTree

int count=0;
int countPreorder (BiTree T)
{ // ÏÈÐò±éÀú¶þ²æÊ÷
   if (T) {
       count++;
        // ·ÃÎʽáµã
      countPreorder(T->lchild);    // ±éÀú×ó×ÓÊ÷
      countPreorder(T->rchild);   // ±éÀúÓÒ×ÓÊ÷
   }
return count;
}
int  Preorder (BiTree T,elemtype x)
{ // ÏÈÐò±éÀú¶þ²æÊ÷
   if (T) {
      if(T->data==x)
          printf("%c",T->data);
        // ·ÃÎʽáµã
      Preorder(T->lchild,x);    // ±éÀú×ó×ÓÊ÷
      Preorder(T->rchild,x);   // ±éÀúÓÒ×ÓÊ÷
   }
return 1;
}

int yeziPreorder (BiTree T)
{ // ÏÈÐò±éÀú¶þ²æÊ÷
    int n=0;
   if (T) {
     if(!T->lchild&&!T->rchild)
        // ·ÃÎʽáµã
     {    count++;
     yeziPreorder(T->lchild);    // ±éÀú×ó×ÓÊ÷
      yeziPreorder(T->rchild);   // ±éÀúÓÒ×ÓÊ÷
   }
   }
return n;
}
int depth(BiTree T)
{
int ldepth,rdepth;
ldepth=depth(T->lchild);
rdepth=depth(T->rchild);
return (ldepth>rdepth?ldepth+1:rdepth+1);
}
int main()
{

BiTree T;   
 createBiTree(T);
 int t1=countPreorder (T);
 printf("%d",t1);
Preorder (T,'A');
int t2=yeziPreorder (T);
 printf("%d",t2);
int t3=depth(T);
printf("%d",t3);
return 0;
}
搜索更多相关主题的帖子: include 
2016-11-09 18:01
相思豆
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-10-25
得分:0 
回复 2楼 书生牛犊
谢谢,代码自己改过来了,你的意思我不太明白。
#include"stdio.h"
#include"malloc.h"
typedef  char elemtype;
typedef struct BiTNode
{
elemtype data;
 struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree  createBiTree(BiTree T) {
   char ch;
   ch=getchar();
    if (ch=='#') T = NULL;
    else{
   
    T=(BiTNode *)malloc(sizeof(BiTNode));
   
      T->data = ch;              
    T->lchild=  createBiTree(T->lchild);   
     T->rchild= createBiTree(T->rchild);   
    }
return T;} // CreateBiTree

int count=0;
int countPreorder (BiTree T)
{ // ÏÈÐò±éÀú¶þ²æÊ÷
   if (T) {
       count++;
        
      countPreorder(T->lchild);   
      countPreorder(T->rchild);  
   }
return count;
}
int  Preorder (BiTree T,elemtype x)
{
   if (T) {
      if(T->data==x)
          printf("%c",T->data);
        
      Preorder(T->lchild,x);   
      Preorder(T->rchild,x);   
   }
return 1;
}
int n=0;
int yeziPreorder (BiTree T)
{
   
   if (T) {
     if(!T->lchild&&!T->rchild)
        
         n++;
     yeziPreorder(T->lchild);   
      yeziPreorder(T->rchild);  
   
   }
return n;
}
int depth(BiTree T)
{
int ldepth,rdepth;
if(!T)
return 0;
ldepth=depth(T->lchild);
rdepth=depth(T->rchild);
return (ldepth>rdepth?ldepth+1:rdepth+1);
}
int main()
{

BiTree T=0;   
 T=createBiTree(T);
 int t1=countPreorder (T);
 printf("二叉树节点的个数是:\n");
 printf("%d\n",t1);
Preorder (T,'A');
int t2=yeziPreorder (T);
printf("叶子节点的个数是:\n");
 printf("%d\n",t2);
int t3=depth(T);
printf("二叉树的深度是:\n");
printf("%d\n",t3);
return 0;
}








2016-11-10 17:32



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




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

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