#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;
}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐