首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求指导啊哪错了,exe停止工作解决方法

2012-04-05 
求指导啊,哪错了,exe停止工作#include stdio.h#include malloc.h# define null 0# define maxsize 100

求指导啊,哪错了,exe停止工作
#include <stdio.h>
#include <malloc.h>
# define null 0
# define maxsize 100
typedef struct node {
char data;
struct node *lchild,*rchild;
}node,*bitree;

bitree Q[maxsize]; 
bitree creat()
{char ch;
int front,rear;
bitree root,s;
root=null;
front=1;
rear=0;
ch=getchar();
while (ch!='#')
{s=null;
if (ch!='@')
{s=(bitree)malloc(sizeof(node));
s->data=ch;
s->lchild=null;
s->rchild=null;}
rear++;
Q[rear]=s;
if (rear==1)
root=s;
else 
{if(s&&Q[front])

 if (rear%2==0)
Q[front]->lchild=s; 
  else Q[front] ->rchild=s; 
  if (rear%2==1) front++; 
  } 
  ch=getchar(); 
  } 
  return root; 
}

void InOrder(bitree root)
{
if(root!=null){
InOrder(root->lchild); /*中序遍历左子树*/
printf("%c",root->data);/*访问根*/
InOrder(root->rchild); /*中序遍历右子树*/
}} 

void main()
{
  printf( "请依次输入字符:" );
  bitree T;

bitree creat();
getchar();
  printf( "中序遍历: ") ;
  InOrder(T);
  


}






[解决办法]
T 未初始化(后来又没有得到确定的值), 运行之后会出现段错误
[解决办法]
局部变量T在使用之前没有初始化。
[解决办法]
楼主是不是要这样。

C/C++ code
#include <stdio.h>#include <malloc.h># define null 0# define maxsize 100typedef struct node {    char data;    struct node *lchild, *rchild;}node, *bitree;bitree Q[maxsize];  bitree creat(){    char ch;    int front,rear;    bitree root,s;    root = null;    front = 1;    rear = 0;    ch = getchar();    while (ch != '#')    {        s = null;        if (ch != '@')        {            s = (bitree)malloc(sizeof(node));            s->data = ch;            s->lchild = null;            s->rchild = null;        }        rear++;        Q[rear] = s;        if (rear == 1)        {            root = s;        }        else          {            if(s && Q[front])                if (rear%2 == 0)                {                    Q[front]->lchild = s;                  }                else                 {                    Q[front] ->rchild = s;                  }                if (rear%2 == 1)                 {                    front++;                  }        }          ch = getchar();      }      return root;  }void InOrder(bitree root){    if(root != null)    {         InOrder(root->lchild);   /*中序遍历左子树*/        printf("%c",root->data); /*访问根*/        InOrder(root->rchild);   /*中序遍历右子树*/    }}  void main(){    printf( "请依次输入字符:" );    bitree T = NULL;    T = creat();    getchar();    printf( "中序遍历: ");    InOrder(T);    getchar();}
[解决办法]
探讨

确实行了,谢谢了

[解决办法]
单步调试

热点排行