队列的定义:
struct QueueRecord
{
int Capacity;
int Front;
int Rear;
int Size;
ElementType *Array;
};
判断队列是否满了:
int IsFull(Queue Q)
{
return Q->Size == Q->Capacity;
}
其中Queue的定义如下:
typedef struct QueueRecord *Queue
创建队列:
Queue CreatQueue(int MaxElements)
{
Queue Q;
if(MaxElements<MinQueueSize):
error("the Queue Size is too small")
Q = malloc( sizeof( struct QueueRecord ) );
if( Q == NULL ):
FatalError( "Out of space!!!" );
Q->Array = malloc( sizeof( ElementType ) * MaxElements );
if( Q->Array == NULL ):
FatalError( "Out of space!!!" );
Q->Capacity = MaxElements;
MakeEmpty( Q );
return Q;
}