The code in Data book (5th Edition) from the 99 page to 100 page
Continuous updates
#define MaxSize 50
typedef int ElemType;
typedef struct {
ElemType data[MaxSize];
int front,rear; //Team head and end pointer
} SqQueue;
//Initialize the queue
void InitQueue(SqQueue *&q) {
q=(SqQueue *)malloc (sizeof(SqQueue));
q->front=q->rear=-1;
}
//Destroy the queue
void DestroyQueue(SqQueue *&q) {
free(q);
}
//Determine if the queue is empty
bool QueueEmpty(SqQueue *q) {
return(q->front==q->rear);
}
//Into the queue
bool enQueue(SqQueue *&q, ElemType e) {
if (q->rear==MaxSize-1) //The team was overflowing
return false;
q->rear++;
q->data[q->rear]=e;
return true;
}
//Out of the queue
bool deQueue(SqQueue *&q,ElemType &e) {
if (q->front==q->rear) //The team empty overflow
return false;
q->front++;
e=q->data[q->front];
return true;
}
如有侵权,请联系作者删除