#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!=NULL)
{
free(q);
}
}
//入队
int InSQType(SQType *q,DATA data)
{
if (q->tail==QUEUELEN)
{
printf("队列满鸟。。。");
return 0;
}
else
{
q->data[q->tail++]=data;
return 1;
}
}
//出队列
DATA *OutSQType(SQType *q)
{
if(q->head==q->tail)
{
数据结构之顺序队列的操作(C语言)
最新推荐文章于 2025-06-23 21:33:17 发布