# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Define queuelen 15
Typedef struct
{
Char name [10];
Int age;
} Data;
Typedef struct
{
Data data [queuelen];
Int head;
Int tail;
} Sqtype;
Sqtype * sqtypeinit ()
{
Sqtype * q;
If (q = (sqtype *) malloc (sizeof (sqtype )))
{
Q-> head = 0;
Q-> tail = 0;
Return Q;
}
Else
{
Return NULL;
}
}
Int sqtypeisempty (sqtype * q)
{
Int temp;
Temp = Q-> head = Q-> tail;
Return temp;
}
Int sqtypeisfull (sqtype * q)
{
Int temp;
Temp = Q-> tail = queuelen;
Return temp;
}
Void sqtypeclear (sqtype * q)
{
Q-> head = 0;
Q-> tail = 0;
}
Void sqtypefree (sqtype * q)
{
If (q)
{
Free (Q );
}
}
Int insqtype (sqtype * q, data)
{
If (Q-> tail = queuelen)
{
Printf ("the queue is full! Operation failed! \ N ");
Return 0;
}
Else
{
Q-> data [q-> tail ++] = data;
Return 1;
}
}
Data * outsqtype (sqtype * q)
{
If (Q-> head = Q-> tail)
{
Printf ("the queue is empty! Operation failed! \ N ");
Exit (0 );
}
Else
{
Return & (Q-> data [q-> head ++]);
}
}
Data * peeksqtype (sqtype * q)
{
If (sqtypeisempty (q ))
{
Printf ("the queue is empty! \ N ");
Return NULL;
}
Else
{
Return & (Q-> data [q-> head]);
}
}
Int sqtypelen (sqtype * q)
{
Int temp;
Temp = Q-> tail-Q-> head;
Return temp;
}
Int main ()
{
Sqtype * queue;
Data data;
Data * data1;
queue = sqtypeinit ();
printf ("Incoming queue operation: \ n");
printf ("input name age: \ n ");
DO
{< br> scanf (" % S % d ", Data. name, & data. age);
If (strcmp (data. name, "0") = 0)
{< br> break;
}< br> else
{< br> insqtype (queue, data);
}< BR >}while (1);
Do
{
Printf ("out queue operation: press any key for out queue operation: \ n ");
Getchar ();
Data1 = outsqtype (Queue );
Printf ("the data in the output queue is (% s, % d) \ n", data1-> name, data1-> age );
} While (1 );
Sqtypefree (Queue );
}