热心人帮小弟我看看这个程序哪错了
热心人帮我看看这个程序哪错了!
#include "stdio.h "
#define NULL 0
#define MAX 100
struct queue *Q;
struct Node
{ int data;
struct Node *lchild,*rchild;
};
typedef struct Node ElemType;
struct list
{ ElemType *data;
struct list *next;
};
struct queue
{ struct list *front,*rear;
int count;
};
struct queue push(ElemType node)
{ struct list *pnew,*p1,*p2;
pnew-> data=node-> data;
pnew-> next=NULL;
if(Q-> count==0) Q-> front=pnew;
else { for(p1=Q-> rear;p1-> next!=NULL;)
{ p2=p1;p1=p1-> next;}
if(p1==Q-> rear) Q-> rear=pnew;
else p1-> next=pnew;
}
Q-> count++;
return Q;
}
ElemType pop()
{ struct list pDel;
ElemType temp;
if(Q-> count==1) Q-> rear =NULL;
pDel=Q-> front;
temp=pDel-> data;
Q-> front=Q-> rear;
Q-> rear=Q-> rear-> next;
Q-> count--;
delete pDel;
pDel=NULL;
return temp;
}
ElemType *creatnode()
{ ElemType *pnode;
pnode=(ElemType *)malloc(sizeof(ElemType));
scanf( "%d ",&pnode-> data);
if(!pnode-> data) pnode=NULL;
return pnode;
}
ElemType *creatTree(ElemType *head)
{ head=creatnode();
if(head)
{head-> lchild=creatTree(head-> lchild);
head-> rchild=creatTree(head-> rchild);
}
return(head);
}
void printTree(ElemType head)
{ while (head!= NULL)
{ print( "%d ",head-> data);
if (head-> lchild!= NULL)
Q =push (Q, head-> lchild);
if (head-> rchild!= NULL)
Q = push(Q, head-> rchild);
if (Q-> count != 0)
printTree(pop(Q),Q);
else return;
}
}
void initi()
{ Q-> front=Q-> rear=NULL;
a-> count=0;
}
main()
{ ElemType *boot=NULL;
initi();
boot=creatTree(boot);
printTree(boot);
printf( "\n ");
getch();
}
那位好心人帮忙看看这个程序应该怎么写?为什么有好多错?好心人帮忙改改!
#include "stdio.h "
#define NULL 0
#define MAX 100
struct queue *Q;
struct Node
{ int data;
struct Node *lchild,*rchild;
};
typedef struct Node ElemType;
struct list
{ ElemType *data;
struct list *next;
};
struct queue
{ struct list *front,*rear;
int count;
};
struct queue push(ElemType node)
{ struct list *pnew,*p1,*p2;
pnew-> data=node-> data;
pnew-> next=NULL;
if(Q-> count==0) Q-> front=pnew;
else { for(p1=Q-> rear;p1-> next!=NULL;)
{ p2=p1;p1=p1-> next;}
if(p1==Q-> rear) Q-> rear=pnew;
else p1-> next=pnew;
}
Q-> count++;
return Q;
}
ElemType pop()
{ struct list pDel;
ElemType temp;
if(Q-> count==1) Q-> rear =NULL;
pDel=Q-> front;
temp=pDel-> data;
Q-> front=Q-> rear;
Q-> rear=Q-> rear-> next;
Q-> count--;
delete pDel;
pDel=NULL;
return temp;
}
ElemType *creatnode()
{ ElemType *pnode;
pnode=(ElemType *)malloc(sizeof(ElemType));
scanf( "%d ",&pnode-> data);
if(!pnode-> data) pnode=NULL;
return pnode;
}
ElemType *creatTree(ElemType *head)
{ head=creatnode();
if(head)
{head-> lchild=creatTree(head-> lchild);
head-> rchild=creatTree(head-> rchild);
}
return(head);
}
void printTree(ElemType head)
{ while (head!= NULL)
{ print( "%d ",head-> data);
if (head-> lchild!= NULL)
Q =push (Q, head-> lchild);
if (head-> rchild!= NULL)
Q = push(Q, head-> rchild);
if (Q-> count != 0)
printTree(pop(Q),Q);
else return;
}
}
void initi()
{ Q-> front=Q-> rear=NULL;
a-> count=0;
}
main()
{ ElemType *boot=NULL;
initi();
boot=creatTree(boot);
printTree(boot);
printf( "\n ");
getch();
}
那位好心人帮忙看看这个程序应该怎么写?为什么有好多错?好心人帮忙改改!