主题:[讨论]出错了!!!!!请那个高手指点一下 小弟谢谢了!!!
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
typedef char Elemtype;
typedef struct Btnode
{
Elemtype daild;
struct Btnode *rchild;
struct Btnode *lchild;
}*BtTree;
struct Lnode
{
struct Btnode *data;
struct Lnode *next;
};
struct Linkqueue
{
struct Lnode *front;
struct Lnode *rear;
};
void Initqueue(struct Linkqueue Q)
{
Q.front=Q.rear=(struct Lnode *)malloc(sizeof(struct Lnode));
Q.front->next=NULL;
}
void Enqueue(struct Linkqueue Q,struct Btnode *elem)
{
struct Lnode *s;
s=(struct Lnode *)malloc(sizeof(struct Lnode));
s->data=elem;
s->next=NULL;
Q.rear->next=s->data;
Q.rear=s;
}
/* Btnode Dlqueue(struct Linkqueue Q)
{
struct Lnode *s;
s=(struct Lnode *)malloc(sizeof(struct Lnode));
if(Q.front->next=NULL)
printf("队列为空!");
else
{
if(Q.front->next=Q.rear)
{
s=Q.rear;
Q.front->next=NULL;
Q.rear=Q.front;
}
else{
s=Q.front->next;
Q.front=Q.front->next;
}
free(s);
return(s->data);
}*/
void CreatBtTree(BtTree BT)
{
char ch;
scanf("c%",&ch);
if(ch=='#')
{
BT=NULL;
}
else
{
BT=(struct Btnode *)malloc(sizeof(struct Btnode));
BT->daild=ch;
CreatBtTree(BT->lchild);
CreatBtTree(BT->rchild);
}
}
void preOrdetBT(BtTree BT)
{
if(BT)
{
printf("c%\n",BT->daild);
preOrdetBT(BT->lchild);
preOrdetBT(BT->rchild);
}
}
void InOrdetBT(BtTree BT)
{
if(BT)
{
PreOrdetBT(BT->lchild);
printf("c%\n",BT->daild);
PreOrdetBT(BT->lchild);
}
}
void PostOrdetBT(BtTree BT)
{
if(BT)
{
PreOrdetBT(BT->lchild);
PreOrdetBT(BT->rchild);
printf("c%",BT->daild);
}
}
main()
{
BtTree BT=NULL;
CreatBtTree(BT);
preOrdetBT(BT);
InOrdetBT(BT);
PostOrdetBT(BT);
}
这个程序就是二叉树的几种遍历的输出,但出了一点错,请指点
#include "malloc.h"
#include "stdlib.h"
typedef char Elemtype;
typedef struct Btnode
{
Elemtype daild;
struct Btnode *rchild;
struct Btnode *lchild;
}*BtTree;
struct Lnode
{
struct Btnode *data;
struct Lnode *next;
};
struct Linkqueue
{
struct Lnode *front;
struct Lnode *rear;
};
void Initqueue(struct Linkqueue Q)
{
Q.front=Q.rear=(struct Lnode *)malloc(sizeof(struct Lnode));
Q.front->next=NULL;
}
void Enqueue(struct Linkqueue Q,struct Btnode *elem)
{
struct Lnode *s;
s=(struct Lnode *)malloc(sizeof(struct Lnode));
s->data=elem;
s->next=NULL;
Q.rear->next=s->data;
Q.rear=s;
}
/* Btnode Dlqueue(struct Linkqueue Q)
{
struct Lnode *s;
s=(struct Lnode *)malloc(sizeof(struct Lnode));
if(Q.front->next=NULL)
printf("队列为空!");
else
{
if(Q.front->next=Q.rear)
{
s=Q.rear;
Q.front->next=NULL;
Q.rear=Q.front;
}
else{
s=Q.front->next;
Q.front=Q.front->next;
}
free(s);
return(s->data);
}*/
void CreatBtTree(BtTree BT)
{
char ch;
scanf("c%",&ch);
if(ch=='#')
{
BT=NULL;
}
else
{
BT=(struct Btnode *)malloc(sizeof(struct Btnode));
BT->daild=ch;
CreatBtTree(BT->lchild);
CreatBtTree(BT->rchild);
}
}
void preOrdetBT(BtTree BT)
{
if(BT)
{
printf("c%\n",BT->daild);
preOrdetBT(BT->lchild);
preOrdetBT(BT->rchild);
}
}
void InOrdetBT(BtTree BT)
{
if(BT)
{
PreOrdetBT(BT->lchild);
printf("c%\n",BT->daild);
PreOrdetBT(BT->lchild);
}
}
void PostOrdetBT(BtTree BT)
{
if(BT)
{
PreOrdetBT(BT->lchild);
PreOrdetBT(BT->rchild);
printf("c%",BT->daild);
}
}
main()
{
BtTree BT=NULL;
CreatBtTree(BT);
preOrdetBT(BT);
InOrdetBT(BT);
PostOrdetBT(BT);
}
这个程序就是二叉树的几种遍历的输出,但出了一点错,请指点