数据结构(C语言实现)之队列(循环队列)

队列的介绍书上都有

认真看书吧

#include "stdio.h"
#define ERROR 0
#define OVERFLOW -2
#define OK 1
typedef int Status;
typedef int QElemType;
#define MAXQSIZE 100
typedef struct 
{
	QElemType *base;
	int front;
	int rear;
}SqQueue;
Status InitQueue(SqQueue &Q)
{
	Q.base=new QElemType[MAXQSIZE];
	if(!Q.base)  return ERROR;
	Q.front=Q.rear=0;
	return OK;
}
Status EnQueue(SqQueue &Q,QElemType e)
{
	if((Q.rear+1)%MAXQSIZE==Q.front)
		return ERROR;
	Q.base[Q.rear]=e;
	Q.rear=(Q.rear +1)%MAXQSIZE;
	return OK;
}
Status OutQueue(SqQueue &Q,QElemType &e)
{
	if(Q.front ==Q.rear)  return ERROR;
	e=Q.base[Q.front];
	Q.front=(Q.front+1)%MAXQSIZE;
	return OK;
}
int QueueLength(SqQueue Q)
{
	return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}



int main(int argc, char* argv[])
{

	return 0;
}

猜你喜欢

转载自blog.csdn.net/sdwujk160507140150/article/details/80054943