问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 1024
#define OVERFLOW -2
#define OK 1
#define ERROR 0
typedef int QElemType;
typedef struct QNode
{
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct
{
QueuePtr front;//队头指针
QueuePtr rear;//队尾指针
}LinkQueue;
void InitQueue(LinkQueue&Q)//构造一个队列
{
Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q.front)exit(OVERFLOW);
Q.front->next=NULL;
return;
}
void EnQueue(LinkQueue&Q,QElemType e)//插入元素e为Q的新队尾
{
QNode *p;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p)exit(OVERFLOW);
p->data=e;
p->next=NILL;
Q.rear->next=p;
Q.rear=p;
return;
}
void DeQueue(LinkQueue&Q,QElemType e)//删除队头元素
{
if(Q.front==Q.rear)return ERROR;
p=Q.front->next;
e=p->data;
Q.front->next=p->next;
if(Q.rear==p)Q.rear=Q.front;
free(p);
return;
}
void DestroyQueue(LinkQueue&Q)//销毁队列
{
while(Q.front)
{
Q.rear=Q.front->next;
free(Q.front);
Q.front=Q.rear;
}
return;
}
int main()
{
int e;
LinkQueue Q;
printf("请输入您的元素:\n");
scanf("%d",&e);
EnQueue(Q,e);
DestroyQueue(Q);
return 0;
}
运行结果及报错内容
C:\Users\86182\Desktop\队列.cpp(37) : error C2065: 'NILL' : undeclared identifier
C:\Users\86182\Desktop\队列.cpp(37) : error C2440: '=' : cannot convert from 'int' to 'struct QNode *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\86182\Desktop\队列.cpp(45) : error C2562: 'DeQueue' : 'void' function returning a value
C:\Users\86182\Desktop\队列.cpp(43) : see declaration of 'DeQueue'
C:\Users\86182\Desktop\队列.cpp(46) : error C2065: 'p' : undeclared identifier
C:\Users\86182\Desktop\队列.cpp(46) : error C2440: '=' : cannot convert from 'struct QNode *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Users\86182\Desktop\队列.cpp(47) : error C2227: left of '->data' must point to class/struct/union
C:\Users\86182\Desktop\队列.cpp(48) : error C2227: left of '->next' must point to class/struct/union
C:\Users\86182\Desktop\队列.cpp(49) : error C2446: '==' : no conversion from 'int' to 'struct QNode *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\86182\Desktop\队列.cpp(49) : error C2040: '==' : 'struct QNode *' differs in levels of indirection from 'int'
执行 cl.exe 时出错.
队列.obj - 1 error(s), 0 warning(s)