#include<stdio.h>
#include<stdlib.h>
#inndef _Queue_h
struct QueueRecord;
typedef struct QqueueRecord *Queue;
struct QueueParameter;
typedef QueueParameter *QueuePar;
QueuePar CreatQueue(int);
int IsEmpty(QueuePar);
int IsFull(QueuePar);
void Enqueue(Element,QueuePar);
void Dequeue(QueuePar);
ElementType Front(QueuePar);
ElementType FrontAndDequeue(QueuePar);
void MakeEmpty(QueuePar);
void DisposeQueue(QueuePar);
#endif
#define SIZE
#define MinQueueSize SIZE
struct QueueRecord
{
ElementType Element;
Queue Next;
};
struct QueueParameter
{
Queue Front;
Queue Rear;
int Size;
int MaxSize;
};
QueuePar CreatQueue(int MaxSize)
{
QueuePar q=(QueuePar)malloc(sizeof(struct QueueParameter));
q->Front=q->Rear=NULL;
q->Size=0;
q->MaxSize=MaxSize;
return q;
}
int IsEmpty(QueuePar q)
{
return (q->Front==NULL&&q->Rear==NULL);
}
int IsFull(QueuePar q)
{
int sum=0;
Queue p=q->Fear;
while(p!=NULL)
{
p=p->Next;
sum++;
}
return sum==q->MaxSize;
}
void Enqueue(Element x,QueuePar q)
{
if(IsFull(q))
printf("Full queue");
else
{
Queue tmp=(Queue)malloc(sizeof(Queue));
tmp->Element=x;
tmp->Next=q->Fear;
q->Fear=tmp;
q->Size++;
}
}
void Dequeue(QueuePar q)
{
if(IsEmpty(q))
printf("The queue is empty");
else
{
if(q->Front==q->Fear)
{free(q->Front); Size--;}
else
{
Queue tmp=q->Front;
Queue p=q->Fear;
while(p->Next!=q->Front)
p=p->Next;
q->Front=p;
free(tmp);
Size--;
}
}
}
ElementType FrontAndDequeue(QueuePar q)
{
ElementType tmp=Front(QueuePar q);
Dequeue(q);
return tmp;
}