33,010
社区成员
发帖
与我相关
我的任务
分享
/*验证队列满时rear的指向*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define MAXSIZE 5
#define OVERFLOW 1
typedef struct
{
int data;
}QElemType;
typedef struct
{
QElemType *base;
int front;
int rear;
}SqQueue;
void InitQueue(SqQueue &Q)
{
Q.base=(QElemType *)malloc(MAXSIZE *sizeof(QElemType));
if(!Q.base)exit(OVERFLOW);
Q.front=0;
Q.rear=0;
}
int main()
{
int i;
SqQueue Q;
InitQueue(Q); /*队列初始化*/
for(i=0;i <MAXSIZE;i++) /*写入*/
{
QElemType elem;
elem.data = i;
Q.base[i]=elem;
Q.rear=(Q.rear+1)%MAXSIZE;
}
printf("Q.base[Q.rear]=%d",Q.base[Q.rear]);
return 0;
}