队列问题,编译出错。
#include<iostream.h>#include<malloc.h>
typedef char ElemType;
typedef struct QNode
{
ElemType data;
struct QNode *next;
}QType;
typedef struct qptr
{
QType *rear;
}LinkQueue;
void InitQueue(LinkQueue*&lq) //初始化队列
{
lq=(LinkQueue*)malloc(sizeof(LinkQueue));
lq->rear=NULL; //初始空队列
}
int QueueEmpty(LinkQueue*lq)
{
if(lq->rear-1==0)
return 1;
else
return 0;
}
void EnQueue(LinkQueue*&lq,ElemType x) //入队
{
QType *s;
s=(QType*)malloc(sizeof(QType)); //创建新结点
s->data=x;
s->next=NULL;
lq->rear=s; //队尾指针指向当向结点
}
int DeQueue(LinkQueue*&lq,ElemType &x) //出队
{
QType *p;
if(QueueEmpty(lq)) //判断是否空队
return 0;
p=lq->next;
x=p->data;
lq->next=p->next; //取出要出队元素的结点
free(p);
return 1;
}
void main()
{
LinkQueue *lq;
ElemType e;
//lq=(LinkQueue*)malloc(sizeof(LinkQueue));
//lq->next=NULL;
InitQueue(lq);
if(QueueEmpty(lq))
cout<<"队空"<<endl;
else
cout<<"队不空"<<endl;
cout<<"a"<<"进队"<<endl;EnQueue(lq,'a');
cout<<"b"<<"进队"<<endl;EnQueue(lq,'b');
cout<<"c"<<"进队"<<endl;EnQueue(lq,'c');
cout<<"d"<<"进队"<<endl;EnQueue(lq,'d');
cout<<"e"<<"进队"<<endl;EnQueue(lq,'e');
if(QueueEmpty(lq))
cout<<"队空"<<endl;
else
cout<<"队不空"<<endl;
cout<<"出队次序:";
while(!QueueEmpty(lq))
{
DeQueue(lq,e);
cout<<e<<" ";
}
}
问题描述:一个带头结点的链表表示队列,并且只设一个指针指向队尾元素的结点(注意不设头指针),写出相应的入队列和出队列的算法,以上是我自己写的代码,编译出错信息为:D:\c语言\Debug\P109 、5.CPP(44) : error C2039: 'next' : is not a member of 'qptr'
D:\c语言\Debug\P109 、5.CPP(12) : see declaration of 'qptr'
D:\c语言\Debug\P109 、5.CPP(46) : error C2039: 'next' : is not a member of 'qptr'
D:\c语言\Debug\P109 、5.CPP(12) : see declaration of 'qptr'
请高手给我说说错在哪里?谢谢。