When there are too many ******************************************************************
Limit µã £° n then limit µä % *********************************************************** ± Ç £ çâ ¼ Ò»  £%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include
#include
#define OK 1;#define ERROR -1;typedef int QElemType;typedef int Status;//¶¨Òå¶ÓÁнڵãtypedef struct QNode{ QElemType data; struct QNode *next;}QNode, *QueuePtr;//¶ÓÁÐtypedef struct{ QueuePtr front; //¶ÓÍ·Ö¸Õë QueuePtr rear; //¶ÓβָÕë}LinkQueue;//³õʼ»¯¶ÓÁÐStatus InitQueue(LinkQueue *q){ q->front = q->rear = (QueuePtr)malloc(sizeof(QNode)); if (!q->front) return ERROR; q->front->next = NULL; return OK;}//Ïú»Ù¶ÓÁÐStatus DestroyQueue(LinkQueue *q){ while(q->front){ q->rear = q->front->next; free(q->front); q->front = q->rear; } return OK;}//²åÈëÔªËØStatus EnQueue(LinkQueue *q, QElemType e){ QueuePtr p = (QueuePtr)malloc(sizeof(QNode)); if(!p) return ERROR; p->data = e; p->next = NULL; q->rear->next = p; //¶ÓÁÐÄβָÏòp q->rear = p; //p¼ÇΪβָÕë return OK;}//³ö¶ÓÁÐStatus DeQueue(LinkQueue *q, QElemType *e){ if(q->front == q->rear) return ERROR; QueuePtr p = q->front->next; //Ö¸Ïò¶ÓÁÐÍ·²¿µÚÒ»¸öÔªËØ *e = p->data; q->front->next = p->next; if(q->rear == p) q->rear = q->front; free(p); return OK;}
³ Õ Ê» ¯ µäê ± ° ò, {0} front ° írear} {{{{******************************* 0, µ±è ¶ Ó 4 ö öö %%%%%%%%%%%%â Í %< %%%%http://www.bkjia.com/kf/ware/vc/ "" target = "_ blank" class = "keylink"> vcD48cD48aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20141203/20141203091316252.png" alt = "\"/>
'{± ± {Ó óááá {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%, ~~~~óáá~±ä~~~~~â {**************** rear <front
Máámámö» Ç ç¡ ° Â úā± £;{μ ± mááá~~iö ~~******************************************** please refer to the following link for more information:
#include
#include
#define OK 1#define ERROR -1#define MAXQSIZE 100 //×î´ó¶ÓÁ㤶Ètypedef int QElemType;typedef int Status;//Ñ»·¶ÓÁÐtypedef struct{ QElemType *base; int front; int rear;}SqQueue;//³õʼ»¯Ñ»·¶ÓÁÐStatus InitQueue(SqQueue *q){ q->base = (QElemType *)malloc(MAXQSIZE * sizeof(QElemType)); if (!q) return ERROR; q->front = q->rear = 0; return OK;}//»ñÈ¡¶ÓÁ㤶Èint QueueLength(SqQueue *q){ return (q->rear - q->front + MAXQSIZE) % MAXQSIZE;}//Èë¶ÓStatus EnQueue(SqQueue *q, QElemType e){ if ((q->rear + 1) % MAXQSIZE == q->front) { return ERROR; } q->base[q->rear] = e; q->rear = (q->rear + 1) % MAXQSIZE; return OK;}//³ö¶ÓStatus DeQueue(SqQueue *q, QElemType *e){ if(q->front == q->rear) return ERROR; *e = q->base[q->front]; q->front = (q->front + 1) % MAXQSIZE; return OK;}