1 //data Structure--queue2 //static queue-implemented with arrays3 //A static queue is usually a circular queue4 //Circular Queue Explanation5 //1. Why does a static queue have to be a circular queue? 6 //2. How many parameters does the loop queue need to determine? 7 /*8 Front and rear9 1) Queue initialization, both the font and rear values are zeroTen 2) Queue non-empty One the font represents the first element of a queue A rear represents the next element of the last valid element of the queue - 3) Queue empty - front and rear values the */ - //3. What are the meanings of the various parameters of the cyclic queue? - //4. How can I tell if the circular queue is empty? - /* + Front is equal to the rear value, the queue must be empty; - */ + //5. How can I tell if the loop queue is full? A /* at 1) Use the flag parameter to determine whether it is full; - 2) Use less of an element - if ((r+1)% array length ==f) - is full; - Else - dissatisfaction; in */ - //6. Circle team included in the team pseudo algorithm explanation to#include <stdio.h> + -typedefstructQueue the { * int*pbase; $ intFront;Panax Notoginseng intRear; - }queue; the + voidInit (queue*); A BOOLEn_queue (queue*,intval); the voidtraverse_queue (queue); + BOOLOut_queue (queue*,int*); - BOOLEmpty_queue (queue*PQ); $ $ intMainvoid) - { - QUEUE Q; theEn_queue (&q,1); -En_queue (&q,1);WuyiEn_queue (&q,1); theInit (&Q); - return 0; Wu } - About voidInit (QUEUE *PQ) $ { -Pq->pbase = (int*)malloc(sizeof(int)*6); -Pq->front =0; -Pq->rear =0; A } + the BOOLEn_queue (queue* PQ,intval) - { $ if(Full_queue (PQ)) the { the return false; the } the Else - { inPq->pbase[pq->rear] =Val; thePq->rear = (Pq->rear +1)%6; the return true; About } the } the the BOOLFull_queue (Queue *PQ) + { - if(Pq->front = = (Pq->rear +1) %6) the {Bayi return true; the } the Else - { - return false; the } the } the the voidTraverse_queue (Queue *PQ) - { the inti = pq->Front; the while(I! = pq->rear) the {94printf"%d",pq->pbase[i]); thei = (i +1) %6; the } the return;98 } About - BOOLEmpty_queue (Queue *PQ)101 {102 if(Pq->rear = = pq->front)103 {104 return true; the }106 Else107 {108 return false;109 } the }111 the BOOLOut_queue (QUEUE*PQ,int*pVal)113 { the if(Empty_queue (PQ)) the { the return false;117 }118 119 inti =0; - while(I! = pq->rear)121 {122*pval = pq->pbase[pq->Front];123Pq->front = (Pq->front +1) %6;124 } the return true;126 }127 - //the specific application of the queue: all time-related is related to the queue
Data structure Queue Instance