当前位置: 代码迷 >> 综合 >> 数据结构(C语言实现)之队列(循环队列)
  详细解决方案

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

热度:18   发布时间:2024-01-15 04:33:19.0

队列的介绍书上都有

认真看书吧

#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;
}