循环队列出队入队运算

#include<stdio.h>
#define MAXSIZE 100
typedef int datatype;
typedef struct node
{
    datatype data[MAXSIZE+1];
    int rear,head;
}sequeue;
sequeue *sq,SQ;
void CIR_INITQUEUE(sequeue *sq)
{
    sq->head=MAXSIZE-1;
    sq->rear=MAXSIZE-1;
    printf("初始化成功\n");
}
int CIR_EMPTY(sequeue *sq)
{
    if(sq->rear==sq->head)
    return 1;
    else return 0;
}

int CIR_GETFRONT(sequeue *sq)//取出循环队列的队头元素 (位置) 
{
    if(CIR_EMPTY(sq))
    {
        printf("队列为空不能执行出队运算");
        return 0; 
    }
    else
    {
        return((sq->head+1)%MAXSIZE);
    }
}

int CIR_ENQUEUE(sequeue *sq,datatype x) //循环队列的入队运算 
{
    if(sq->head==(sq->rear+1)%MAXSIZE)
    {
        printf("队列已满");
        return 0;
    }
    else
    {
        sq->rear=(sq->rear+1)%MAXSIZE;
        sq->data[sq->rear]=x;
        return 1;
    }
}
datatype CIR_DEQUEUE(sequeue *sq)
{
    if(CIR_EMPTY(sq))
    {
        printf("队列为空");
        return 0;
    }
    else
    {    sq->head=(sq->head+1)%MAXSIZE;
        printf("%d",sq->data[sq->head]);
        return (sq->data[sq->head]);
    }
}
int main()
{sq=&SQ;
datatype x=5;
void CIR_INITQUEUE(sequeue *sq); 
int CIR_EMPTY(sequeue *sq);
int CIR_GETFRONT(sequeue *sq);
int CIR_ENQUEUE(sequeue *sq,datatype x);
datatype CIR_DEQUEUE(sequeue *sq);
CIR_INITQUEUE(&SQ);
scanf("%d",&x);
CIR_ENQUEUE(&SQ,x);
CIR_DEQUEUE(&SQ);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值