/ * SequenceQueue.c * / / * the queues * / #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define the MAXSIZE 100 / * order circular queue data structure * / / * a circle, front head of the queue points, rear end of the queue points to * / / * Front -> ... -> REAR Data [0] -> Data [...] -> Data [n-] * / typedef struct { int Data [ the MAXSIZE]; int REAR, Front; int NUM; / * number of queue elements * / } SeqQueue; void interface ( void ); / * order list function declarations * / SeqQueue * initializeSeqQueue (); BOOL isFullSeqQueue (SeqQueue * ); BOOL isEmptySeqQueue (SeqQueue * ); void inSeqQueue (SeqQueue *, int ); int outSeqQueue (SeqQueue * ); int main () { SeqQueue * sq. = initializeSeqQueue (); int In Flag, Number; interface (); for (;;) { the printf ( " the Command: " ); Scanf ("%d", &flag); switch(flag){ case 0: printf("Bye!\n"); return 0; break; case 1: if(isFullSeqQueue(sq)) printf("Queue is full!\n"); else{ printf("Enter number: "); scanf("%d", &number); inSeqQueue(sq, number); } break; case 2: if(isEmptySeqQueue(sq)) printf("Queue is empty!\n"); else{ printf("value: %d\n", outSeqQueue(sq)); } break; } } return 0; } void interface(void){ puts("+********************+" ); The puts ( " + 0, quit Exit + " ); the puts ( " + 1, in the team + " ); the puts ( " + 2, a team OUT + " ); the puts ( " + ***** *************** + " ); } / * sequence listing functions for * / / * initialize the order list, the list is empty, front and read are -1, num 0 * / SeqQueue * initializeSeqQueue () { SeqQueue * sq. = (SeqQueue *) the malloc ( the sizeof (SeqQueue)); sq. -> = SQ-Front> REAR = - . 1; Sq. -> NUM = 0 ; return sq.; } / * Is determined whether the queue is empty * / BOOL isEmptySeqQueue (SeqQueue * sq.) { IF (SQ-> NUM == 0 ) return to true ; return to false ; } / * Analyzing queue is full * / BOOL isFullSeqQueue (SeqQueue * sq.) { iF (SQ-> == NUM the MAXSIZE) return to true ; return to false ; } / * enqueue * / void inSeqQueue(SeqQueue *sq, int number){ /* 循环队列,取余MAXSIZE */ sq->rear = sq->rear+1 % MAXSIZE; sq->data[sq->rear] = number; sq->num++; } /* 出队 */ int outSeqQueue(SeqQueue *sq){ sq->front = sq->front+1 % MAXSIZE; sq->num--; return sq->data[sq->front]; }