# Include <stdio. h> # include <stdlib. h> struct queuerecord {int capacity; int front; int rear; int size; char * array ;}; struct queuerecord * createqueue (INT size) {char * P; struct queuerecord * queue; P = (char *) malloc (size); queue = (struct queuerecord *) malloc (sizeof (struct queuerecord); queue-> capacity = size; queue-> size = 0; queue-> array = P; queue-> front = 0; queue-> rear = 0;} int isfull (struct queuerecord * q) {return Q-> size = Q-> capacity;} int isempty (struct queuerecord * q) {return Q-> size = 0;} int succ (INT value, struct queuerecord * q) {value ++; If (value = Q-> capacity) {value = 0;} return value;} void enqueue (char X, struct queuerecord * q) {If (isfull (q) {printf ("full \ n"); return;} Q-> size ++; q-> array [q-> rear] = x; q-> rear = succ (Q-> rear, q);} int dequeue (struct queuerecord * q) {int X; If (isempty (q) {printf ("Empty \ n"); Return-1 ;}else {q-> size --; X = Q-> array [q-> front]; q-> front = succ (Q-> front, q); Return x ;}} void queue_view (struct queuerecord * q) {int I; int TMP; printf ("front = % d \ n", Q-> front ); printf ("Rear = % d \ n", Q-> rear); printf ("size = % d \ n", Q-> size); for (I = 0; I <q-> size; I ++) {TMP = Q-> front + I; If (TMP> = Q-> capacity) {TMP = TMP-Q-> capacity;} printf ("No [% d] = % d \ n", TMP, Q-> array [TMP]);} int main () {int I; struct queuerecord * queue; queue = createqueue (5); for (I = 0; I <5; I ++) {enqueue (I, queue);} queue_view (Queue); for (I = 0; I <2; I ++) {printf ("de [% d] = % d \ n ", i, dequeue (Queue);} enqueue (5, queue); enqueue (6, queue ); printf ("******************* \ n"); queue_view (Queue );}