我是靠谱客的博主 潇洒睫毛,这篇文章主要介绍数组存放循环队列,现在分享给大家,希望可以做个参考。

/*以数组存放循环队列,tag=0或1区分rear和front相等时
队空或者队满,编写相应的入队和出队算法。
*/
#ifndef PCH_H
#define PCH_H
#include<stdio.h>
#include<iostream>
#include<malloc.h>
#include<cstdlib>//包含exit头文件
#include<math.h>
#define OK 1;
#define ERROR 0;
#define MAXSIZE 10;
typedef int Status;
typedef struct
{
    int Q[10];//以数组存放队列中的元素
    int front; int rear;//头指针和尾指针相同时,由tag判断队满还是空。
    int tag;
}SqQueue;
// TODO: 添加要在此处预编译的标头
Status enqueue(SqQueue &Q,int e);//入队
Status dequeue(SqQueue &Q,int e);//出队
#endif //PCH_H
Status enqueue(SqQueue & Q, int e)
{
    if (Q.tag!=1)
    {
        Q.Q[Q.rear] = e;
        Q.rear = (Q.rear + 1) % MAXSIZE;
        return OK;
    }
    return ERROR;
}

Status dequeue(SqQueue & Q, int &e)
{
    if (Q.tag == 0) return ERROR;
    e = Q.Q[Q.front];
    Q.front = (Q.front + 1) % MAXSIZE;
    return OK;
}

最后

以上就是潇洒睫毛最近收集整理的关于数组存放循环队列的全部内容,更多相关数组存放循环队列内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(130)

评论列表共有 0 条评论

立即
投稿
返回
顶部