队列操作的练手程序如下【额,说明一点,这是练手时候写的,很可能会有错误,而且鲁棒性可能也不咋地……】
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define QUEUELEN 15
//SQType *SQTypeInit(void);
       
//
                    //生成队列。
//int SQTypeIsEmpty(SQType *q);
   
//
                   //判断空队列。
//int SQTypeIsFull(SQType *q);
    
//
                   //判断满队列。
//void SQTypeClear(SQType *q);
   
//
                  //清空队列。
//void SQTypeFree(SQType *q);
  
//
                  //释放队列。
//int InSQType(SQType *q,DATA data);
//
                  //入队列。
//DATA *OutSQType(SQType *q);
//
                  //出队列。
//DATA *PeekSQType(SQType *q);
//
                 //读结点数据。
//int SQTypeLen(SQType *q);
                 //计算队列长度。
//////////////////////////////////////////////////主函数///////////////////////////////
////////////////////////////////定义队列结构//////////////////////
typedef struct 
{
    char name[10];
    int age;
}DATA;
typedef struct 
{
    DATA data[QUEUELEN];
    int head;
    int tail;
}SQType;
///////////////////////////////定义函数/////////////////////
/*
                                        __________________________________
                                              生成队列结构
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
SQType *SQTypeInit(void)
{
    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!=NULL)
    {
        free(q);
    }
}
/*
                                          ______________________________
                                                入队列
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
int InSQType(SQType *q,DATA data)
{
    if(q->tail==QUEUELEN)
    {
        printf("队列已满!操作失败!\n");
        return 0;
    }
    else
    {
        q->data[q->tail++]=data;
        /////////////////////////
        return 1;
    }
}
/*
                                               _________________________________
                                                     出队列
                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
DATA *OutSQType(SQType *q)
{
    if(q->head==q->tail)
    {
        printf("队列已空!操作失败!\n");
        exit (0);
    }
    else
    {
        return &(q->data[q->head++]);
    }
}
/*
                                                ________________________________
                                                      读结点数据
                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
DATA *PeekSQType(SQType *q)
{
    if(SQTypeIsEmpty(q))
    {
        printf("\n空队列!\n");
        return NULL;
    }
    else
    {
        return &(q->data[q->head]);
    }
}
/*
                                     ______________________________
                                          计算队列长度
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
int SQTypeLen(SQType *q)
{
    int temp;
    temp=q->head-q->tail;
    return temp;
}
void main()
{
    SQType *stack;
    DATA data;
    DATA *data1;
    stack=SQTypeInit();
    printf("输入姓名 年龄进行入队列操作:\n");
    do
    {
        scanf("%s%d",data.name,&data.age);
        if(strcmp(data.name,"0")==0)
        {
            break;
        }
        else
        {
            InSQType(stack,data);
        }
    }while (1);
    do
    {
        printf("出队列操作:按任意键进行出队列操作:\n");
        getchar();
        data1=OutSQType(stack);
        printf("出队列的数据是(%s,%d)\n\n",data.name,&data.age);
    }while(1);
    SQTypeFree(stack);
}