Tag: Exit queue IMA Scan causes logs status include Ror
————————————————————————————————————————————
If you use a sequential table as a queue, you cannot continue inserting new tail elements when you are in the right state, otherwise the program code will be corrupted because the array is out of bounds.
This results in a circular queue implemented by the list, which can be inserted into a new tail element only if the queue is not full.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Basic operation:
/* To define a linked list queue */
Defines the structure in which front indicates the team header position, rear indicates the end of the team, and the base pointer is used to request space and hold data.
/* Initialize Queue */
Use pointer *base to request 100 memory spaces, front and rear 0 respectively, when the queue is empty
/* judging empty or full */
Implementation code:
1#include <stdio.h>2#include <stdlib.h>3 #defineOK 14 #defineERROR 05 #defineOVERFLOW-26 #defineMaxqsize 1007typedefintStatus;8typedefintQelemtype;9typedefstructNodeTen { OneQelemtype *Base;//initialize dynamic allocation of storage space A intFront; - intRear; - } sqqueue; theStatus Initqueue (Sqqueue *Q) - { -Q->Base= (Qelemtype *) malloc (maxqsize *sizeof(Qelemtype)); - if(! Q->Base) + exit (OVERFLOW); -Q->front = Q->rear =0; + returnOK; A } atStatus EnQueue (Sqqueue *Q, Qelemtype elem) - { - //queue is empty when 1%100==1, queue full (99+1)%100==0, up to 99 elements - if((Q->rear +1)% Maxqsize = = (q->front)) - returnERROR; -Q->Base[Q->rear] =Elem; inQ->rear = (Q->rear +1)% Maxqsize;//rear is always circulating in 0-100 - returnOK; to } +Status Outqueue (Sqqueue *q, Qelemtype *e) - { the if(Q->front = = q->rear) * returnERROR; $*e = q->Base[q->Front];Panax NotoginsengQ->front = (Q->front +1) %maxqsize; - returnOK; the } + Status PrintQueue (sqqueue Q) A { theprintf"The queue is:"); + for(inti = Q.front; i < q.rear; ++i) -printf"%d"Q.Base[i]); $ returnOK; $ } - intMain () - { the sqqueue queue; - qelemtype Elem;Wuyi inti; theInitqueue (&queue); -printf"Input:"); Wu while(SCANF ("%d", &elem)! =EOF) -EnQueue (&queue, elem); About PrintQueue (queue); $ /*Enter the number of queues to be out*/ -printf"\noutput:"); -scanf"%d", &i); - while(I! =0) A { +Outqueue (&queue, &elem); thei--; - } $ PrintQueue (queue); the returnOK; the}
C Language Implementation Loop queue (basic operation and illustration)