Queue:
#ifndef _queue_hstruct queuerecord;typedef struct queuerecord *queue;int empty ( QUEUE Q); Int isfull (QUEUE Q); Queue createqueue (int maxelements); Void disposequeue (queue q); Void MakeEmpty (Queue  Q); Void enqueue (ELEMENTTYPE X, QUEUE Q); Elementtype front (QUEUE Q); Void dequeue (QUEUE Q); Elementtype frontanddequeue (queue q); #endif #define minqueuesize (5) Struct QueueRecord { int capacity; int front; int Rear; int Size; ElementType *Array; }; int isempty (queue q) { return Q->Size==0; } void makeempty (queue q) { q->size=0; q->front=1; q->rear=0; }
From the program above you can see the array of arrays:
Rear=0,front=1. At this time: if data is inserted (queue enqueue), then rear to the right one bit, that is rear++; if the data is deleted (out of the team Dequeue), front to the right, that is front++;
Initial time rear=0,front=1.
The queue defined above is not a circular queue, so: When the queue is empty, size=0,rear=front-1; When the queue is full, size! =0,rear=0.
"Data structure and algorithm analysis--c language description" after reading note 6