请c高手帮忙看下问题错在哪里编写程序,建立一个循环队列,队列的数据类型为整形,队列的大小采用宏定义。

来源:百度知道 编辑:UC知道 时间:2024/07/09 04:56:06
#include<stdio.h>
#include<stdlib.h>
#define MAXQSIZE 100
typedef struct{
QElemType *base;
int front;
int rear;
}sqQueue;

Status InitQueue ( SqQueue &q ) //初始化空循环队列 q
{ q . base=(QElemType *)malloc(sizeof(QElemType)
* QUEUE_MAXSIZE); //分配空间
if (!q.base) exit(OVERFLOW);//内存分配失败,退出程序
q.front =q.rear=0; //置空队列
return OK;
} //InitQueue;

int QueueLength(SqQueue q)
return(Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}

Status EnQueue(SqQueue &q, QElemType e)
{//向循环队列 q 的队尾加入一个元素 e
if ( (q.rear+1) % QUEUE_MAXSIZE = = q.front )
return ERROR ; //队满则上溢,无法再入队
q.base [ q.rear ] = e; //新元素e入队
q.rear = ( q . rear + 1 ) % QUEUE_MAXSIZE; //指针后移
return OK;
}// EnQueue;

Status DeQueue ( SqQueue &q, QElemType &e)
{//若队列不空,删除循环队列q的队头元素,
//由 e 返回其值,并返回

其实没什么大问题,只是缺了一些头文件,编译器找不到QElemType的定义,需要将相关的头文件包含进来,可能还要添加#include "stdafx.h"。

有几个都是没打“;”分号```!!