#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
/*
**循环队列它的容量是固定的,并且它的对头和队尾指针都可以随着元素
**入队列而发生改变。
*/
typedef char ElemType;
typedef struct
{
ElemType *base;//用于存放内存分配基础地址,也可用数组存放
int front;
int rear;
}cycleQueue;
/*
**循环队列的初始化
*/
void InitQueue(cycleQueue *q)
{
q->base=(ElemType *)malloc(MAXSIZE*sizeof(ElemType));
if(!q->base)
exit(0);
q->front=q->rear=0;
}
/*
**入队列操作
*/
void InsertQueue(cycleQueue *q,ElemType e)
{
if((q->rear+1)%MAXSIZE==q->front)
return;
q->base[q->rear]=e;
q->rear=(q->rear+1)%MAXSIZE;
}
/*
**出队列操作
*/
void DeleteQueue(cycleQueue *q,ElemType *e)
{
if(q->front==q->rear)
return;
*e=q->base[q->front];
q->front=(q->front+1)%MAXSIZE;
}
int main()
{
printf("Hello world!\n");
return 0;
}
数据结构与算法之循环队列
最新推荐文章于 2021-07-27 10:01:47 发布