ride in a car:帮一下忙啊!!!!

来源:百度文库 编辑:高校问答 时间:2024/04/18 16:26:05
typedef char QElemType;
typedef int Status;
typedef int QueuePtr;
#define OK 1
#define ERROR 0
#define OVERFLOW -1

#include "stdlib.h"

#include "malloc.h"
#include "stdio.h"

typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
typedef struct Qnode
{
QElemType data;
struct Qnode *next;
}Qnode,* QueuePtr;
Status QueueEmpty(LinkQueue q)
{
return ((q.front==NULL)&& (q.rear==NULL));
}

Status InitQueue (LinkQueue &Q)
{
Q.front=Q.rear=(QueuePtr)malloc(sizeof(Qnode));
if(!Q.front) return (OVERFLOW);
Q.front->next=NULL;
return OK;
}

Status DestroyQueue (LinkQueue &Q)
{
while(Q.front)
{
Q.rear=Q.front->next;
free(Q.front);
Q.front=Q.rear;
}
return OK;
}
Status EnQueue (LinkQueue &Q,QElemType e)
{

Qnode *P=(QueuePtr)malloc(sizeof(Qnode));
if(!P) return (OVERFLOW);
P->data=e;
P->next=NULL;
Q.rear->next=P;
Q.rear=P;
return OK;
}
Status DeQueue (LinkQueue &Q,QElemType &e)
{

if(Q.front==Q.rear)
return ERROR;
Qnode *p=Q.front->next;
e=p->data;
Q.front->next=p->next;
if(Q.rear == p)
Q.rear=Q.front;
free(p);
return OK;
}

void main()
{
LinkQueue q;
char x='e',y='c';
if(InitQueue(q)!= OK)
printf("initqueue is fail\n");
else
{
EnQueue(q,'h');
EnQueue(q,'r');
EnQueue(q,y);
DeQueue(q,x);
EnQueue(q,x);
DeQueue(q,x);
EnQueue(q,x);
EnQueue(q,'a');
while(!QueueEmpty(q))
{
DeQueue(q,y);
printf("%c",y);
}
printf("%c\n\n",x);
}
}
ompiling...
linkqueue.cpp
E:\浙大数据结构\自己写的程序\linkqueue.cpp(23) : error C2040: 'QueuePtr' : 'struct Qnode *' differs in levels of indirection from 'int'
E:\浙大数据结构\自己写的程序\linkqueue.cpp(33) : error C2227: left of '->next' must point to class/struct/union
E:\浙大数据结构\自己写的程序\linkqueue.cpp(41) : error C2227: left of '->next' must point to class/struct/union
E:\浙大数据结构\自己写的程序\linkqueue.cpp(42) : error C2664: 'free' : cannot convert parameter 1 from 'int' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\浙大数据结构\自己写的程序\linkqueue.cpp(51) : error C2440: 'initializing' : cannot convert from 'int' to 'struct Qnode *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\浙大数据结构\自己写的程序\linkqueue.cpp(55) : error C2227: left of '->next' must point to class/struct/union
E:\浙大数据结构\自己写的程序\linkqueue.cpp(55) : error C2227: left of '->next' must point to class/struct/union
E:\浙大数据结构\自己写的程序\linkqueue.cpp(56) : error C2440: '=' : cannot convert from 'struct Qnode *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
E:\浙大数据结构\自己写的程序\linkqueue.cpp(64) : error C2227: left of '->next' must point to class/struct/union
E:\浙大数据结构\自己写的程序\linkqueue.cpp(66) : error C2227: left of '->next' must point to class/struct/union
E:\浙大数据结构\自己写的程序\linkqueue.cpp(67) : error C2446: '==' : no conversion from 'struct Qnode *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
E:\浙大数据结构\自己写的程序\linkqueue.cpp(67) : error C2040: '==' : 'int' differs in levels of indirection from 'struct Qnode *'
Error executing cl.exe.

linkqueue.obj - 11 error(s), 0 warning(s)高手帮忙看一下错在哪啊!!感激不尽!!!!

把开头的typedef int QueuePtr;去掉,这么写不就重复声明了么。