求顺序循环队列的实现和相关操作的C语言程序代码。。。。。。。
1条回答 默认 最新
- cloudyzhao 2017-08-29 05:19关注
#include
#include#define OK 1
#define ERROR 0#define QUEUE_SIZE 100
typedef int Status;
typedef int ElemType;typedef struct Qnode
{
ElemType base;
int front;
int rear;
int count;
} Qnode;
Status Init(Qnode &qq)
{
qq.base = (ElemType)malloc(QUEUE_SIZE * sizeof(ElemType));
if (qq.base == NULL) return ERROR;
qq.front = 0;
qq.rear = 0;
qq.count = 0;
return OK;
}Status EnQueue(Qnode &qq, ElemType e)
{if ((qq.rear + 1) % QUEUE_SIZE == qq.front) return ERROR; qq.base[qq.rear] = e; qq.rear = (qq.rear + 1)%QUEUE_SIZE; qq.count++; return OK;
}
Status DeQueue(Qnode &qq, ElemType &e)
{
if (qq.rear == qq.front)
return ERROR;
e = qq.base[qq.front];
qq.front = (qq.front + 1) % QUEUE_SIZE;
qq.count--;
return OK;
}Status GetTop(Qnode &qq, ElemType &e)
{
if (qq.rear == qq.front)
return ERROR;
e = qq.base[qq.front];
return OK;
}
Staus Destroy(Qnode qq)
{
free(qq.base);
qq.base = NULL;
qq.count = 0;
return OK;
}
int main()
{
Qnode qq;
Init(qq);
int m, i;
printf("how many nums?\n");
scanf("%d", &m);
for (i = 0; i < m; i++)
{
int e;
scanf("%d", &e);
EnQueue(qq, e);
}
int e;
GetTop(qq, e);
printf("%d\n" , e);
for (i = 0; i < m; i++)
{
DeQueue(qq, e);
printf("%d ", e);
}
printf("\n");
system ("pause");
return 0;
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 3
悬赏问题
- ¥15 #MATLAB仿真#车辆换道路径规划
- ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
- ¥15 数据可视化Python
- ¥15 要给毕业设计添加扫码登录的功能!!有偿
- ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
- ¥15 微信公众号自制会员卡没有收款渠道啊
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条
- ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘