#include #include#define OK 1#define ERROR 0typedef int Status; Status is the type of the function, whose value is the function result status code, such as OK, such as typedef int QELEMTYPE; #define MAXQSIZE 100//Maximum queue Length (for circular queues, the maximum queue length is reduced by 1) typedef Struct{ qelemtype *base;//Initialize dynamically allocated storage space int front;//head pointer, if the queue is not empty, Point to the queue header element int rear; Tail pointer, if the queue is not empty, point to the next position of the tail element of the queue} sqqueue; //Create queue status Initqueue (Sqqueue &q) {//Constructs an empty queue Q, the queue has a predefined size of maxqsize q.base= (Qelemtype *) malloc (sizeof (sqqueue) *maxqsize); if (Q.base= =null) return Error; q.front=q.rear=0; return OK;} //Queue Status EnQueue (Sqqueue &q,qelemtype e) {//Insert element E for Q's new team tail element if ((q.rear+1)% Maxqsize==q.front) return ERROR; //not insert q.base[q.rear]=e; q.rear= (Q.rear+1)% Maxqsize; return ok; } //Team Status DeQueue (Sqqueue &q, Qelemtype &AMp;e) {//If the queue is not empty, delete the team header element of Q, return its value with E, and return OK; return Error if (q.front==q.rear) return error; e=q.base[q.front]; q.front= (q.front+1)%MAXQSIZE; return OK;} //header element Status GetHead (Sqqueue Q, Qelemtype &e) {//If the queue is not empty, return the team head element with E and return OK, otherwise return error if (q.front==q.rear) return Ok; e=q.base[q.front]; return OK;} //counts the number of elements in the queue int queuelength (Sqqueue Q) { return (q.rear-q.front+maxqsize)%MAXQSIZE; } //determines whether the queue is empty status Queuetraverse (Sqqueue Q) {//If the queue is not empty, the queue elements are output from the head to the end of the team, and return OK; otherwise error. int i; i=q.front; if (i==Q.rear) printf ("The Queue is Empty! "); //please fill in the blanks else { printf ("The Queue is:"); while (I!=q.rear) //please fill in the blanks { printf ("%d", q.base[i]); //please fill in the blanks i = (i+1)%MAXQSIZE; //please fill in the blanks } } printf ("\ n"); return OK;} //main function int main () { int a; sqqueue s; Qelemtype x, E; if (Initqueue (S)) //determine if the order table was created successfully, please fill in the blanks { printf ("A Queue has created.\n"); } while (1) { printf ("1:enter \n2:delete \n3:get the Front \n4:return the Length of the queue\n5:load the Queue\n0:exit\nplease CHoose:\n ");         SCANF ("%d ", &a); switch (a) { case 1: scanf ("%d", &X); if (! EnQueue (s,x)) printf ("Enter error!\n"); To determine whether the queue is lawful, please fill in the Blanks else printf ("The Element%d is successfully entered!\n ", X); break; case 2: if (! DeQueue (s,e)) printf ("Delete error!\n"); To determine if the team is legal, please fill in the Blanks else printf ("The Element%d is successfully deleted!\n ", e); break; case 3: if (! GetHead (s,e)) printf ("Get Head error!\n"); To determine if get Head is legal, please fill in the Blanks else printf ("The head Of the The Queue is%d!\n ", e); break; case 4: printf ("The Length of the Queue is%d!\n", Queuelength (S)); //please fill in the blanks break; case 5: Queuetraverse (S); Please fill in the blanks break; case 0: return 1; } }}
Basic operations for Sequential loop queues