CycleQueue--循环队列(c语言简单实现)

本文介绍了一种使用C语言实现的循环队列数据结构。详细展示了初始化队列、插入元素及弹出元素等基本操作的代码实现。通过定义结构体和使用预编译宏来控制队列大小,实现了队列的基本功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 #include<stdlib.h>
 2 
 3 #define SIZE 10
 4 typedef char ele;
 5 
 6 typedef struct{
 7     ele *e;
 8     int front;
 9     int rear;
10 }cycleQueue;
11 
12 
13 //initQueue
14 void initQueue(cycleQueue *q){
15     q = (cycleQueue *)malloc(sizeof(cycleQueue));
16     q->e = (ele *)malloc(SIZE*sizeof(ele));
17     q->front=q->rear=0;
18 }
19 
20 //insertQueue
21 void insertQueue(cycleQueue *q,ele e){
22     if(q->front==(q->rear+1)%SIZE)return;
23     q->e[q->rear]=e;
24     q->rear=(q->rear+1)%SIZE;
25 }
26 
27 //popQueue
28 ele popQueue(cycleQueue *q){
29     if(q->front==q->rear)return NULL;
30     ele e = q->e[q->front];
31     q->front=(q->front+1)%SIZE;
32     return e;
33 }

 

转载于:https://www.cnblogs.com/mozhuhao/p/4486741.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值