#include <stdio.h> #define maxn 1000 //队列ADT---数组实现 struct queueRecord; typedef struct queueRecord *Queue; typedef int elementType; int isEmpty(Queue Q); int isFull(Queue Q); Queue creatQueue(int maxn); void disposeQueue(Queue Q); void makeEmpty(Queue Q); void enqueue(elementType x, Queue Q); //element type elementType front(Queue Q); void dequeue(Queue Q); elementType frontAndDequeue(Queue Q); struct queueRecord{ int capacity; int front; int rear; int size; ElementType *arr; }; /*---以上是队列的类型声明---*/ int isEmpty(Queue Q){ return Q->size == 0; } void makeEmpty(Queue Q){ Q->size = 0; Q->front = 1; Q->rear = 0; } static int succ(int value, Queue Q){ if(++value == Q->capacity) value = 0; return value; } /*---在队列未满的情况下获取rear下标---*/ void enqueue(elementType x, Queue Q){ if(isFull(Q)) Error("Full Queue!"); ++Q->size; Q->rear = succ(Q->rear, Q); Q->arr[Q->rear] = x; } /*---入队---*/
原文地址:http://blog.csdn.net/chang_mu/article/details/26618599