代码如下:
#include <iostream>
using namespace std;const int MAXQSIZE = 10;typedef int ElemType;typedef struct
{ElemType *base;int front;int rear;
}SqQueue;bool initQueue(SqQueue &q)
{q.base = new ElemType[MAXQSIZE];if (!q.base) return false;q.front = q.rear = 0;return true;
}bool destroyQueue(SqQueue &q)
{delete[] q.base;q.front = q.rear = 0;return true;
}bool clearQueue(SqQueue &q)
{q.rear = q.front;return true;
}bool queueEmpty(SqQueue q)
{if (q.front == q.rear) return true;return false;
}bool getHead(SqQueue q, ElemType &e)
{ if (q.front == q.rear) return false;e = q.base[q.front];return true;
}int queueLength(SqQueue q)
{return (q.rear - q.front + MAXQSIZE) % MAXQSIZE;
}bool enQueue(SqQueue &q, ElemType e)
{if ((q.rear + 1) % MAXQSIZE == q.front) return false;q.base[q.rear] = e;q.rear = (q.rear + 1) % MAXQSIZE;return true;
}bool deQueue(SqQueue &q, ElemType &e)
{if (q.front == q.rear) return false;e = q.base[q.front];q.front = (q.front + 1) % MAXQSIZE;return true;
}void queueTraverse(SqQueue q)
{int i = q.front;while (i != q.rear){cout << q.base[i] << " ";i = (i + 1) % MAXQSIZE;}cout << endl;
}int main()
{int n;cin >> n;SqQueue q;initQueue(q);int a;for (int i = 0; i < n; i++){cin >> a;enQueue(q, a);}queueTraverse(q);deQueue(q, a);deQueue(q, a);queueTraverse(q);cout << queueLength(q) << endl;return 0;
}