循环队列
#include<iostream> #define maxsize 1000 using namespace std; typedef struct { int *base; int front; int rear; }SqQueue; void InitQueue(SqQueue &q) { q.base = new int[maxsize]; if (!q.base) return; q.front = q.rear = 0; } int QueueLength(SqQueue q) { return (q.rear - q.front + maxsize) % maxsize; } void EnQueue(SqQueue &q,int e) { if ((q.rear + 1) % maxsize == q.front) { return; } q.base[q.rear] = e; q.rear = (q.rear + 1) % maxsize; } void DeQueue(SqQueue &q, int e) { if (q.front == q.rear) return; e = q.base[q.front]; q.front = (q.front + 1) % maxsize; }