Code:
# Include
# Include
# Define MaxSize 5 typedef char ElemType; typedef struct {ElemType data [MaxSize]; int front, rear;} SqQueue; // initialize void InitQueue (SqQueue * & q) {q = (SqQueue *) malloc (sizeof (SqQueue); q-> front = q-> rear = 0;} // destroy the queue void DestroyQueue (SqQueue * & q) {free (q);} // empty bool QueueEmpty (SqQueue * q) {return (q-> front = q-> rear );} // enter bool enQueue (SqQueue * & q, ElemType e) {if (q-> rear + 1) % MaxSize = q-> front) return false; q-> rear = (q-> rear + 1) % MaxSize; q-> data [q-> rear] = e; return true ;} // departure bool deQueue (SqQueue * & q, ElemType & e) {if (q-> front = q-> rear) return false; q-> front = (q-> front + 1) % MaxSize; e = q-> data [q-> front]; return true ;} // reverse void ReverseQueue (SqQueue * q) {int len = (q-> rear-q-> front + MaxSize) % MaxSize); int a [MaxSize]; elemType e; for (int I = 0; I
Front = q-> rear = 0; for (int j = len-1; j> = 0; j --) {q-> rear = (q-> rear + 1) % MaxSize; q-> data [q-> rear] = a [j] ;}} void main () {ElemType e; SqQueue * q; InitQueue (q ); if (! EnQueue (q, 'A') printf ("full team"); if (! EnQueue (q, 'B') printf ("full team"); if (! EnQueue (q, 'C') printf ("full team"); if (! EnQueue (q, 'D') printf ("full team"); printf ("\ n "); printf ("a, B, c, and d enter the annular queue \ n"); ReverseQueue (q); printf ("reverse: \ n"); while (! QueueEmpty (q) {deQueue (q, e); printf ("% c", e) ;} DestroyQueue (q );}