首页 > 编程知识 正文

c语言实现循环队列,循环队列Q最多可存储

时间:2023-05-06 05:39:46 阅读:132380 作者:156

#include'bits/stdc .h ';

#define max 100

//*

循环队列的密钥rear位于front的底部,通过区分完整和空值,巧妙构建循环

*/

类型结构队列{

int *base;

int front;

int rear;

(}队列;

语音堆栈(队列堆栈) {

sack.base=(int* ) malloc ) sizeof(int ) *max );

if (! stack.base )

{printf (“分配存储空间失败。 n "

返回; }

stack.front=stack.rear=0;

}

void push (队列队列,int e ) {

if(queue.front==() (queue.rear1) % max ) ) )

printf (“队列已满,无法再插入元素”)

返回;

} else{

queue.base[queue.rear]=e;

queue.rear=(queue.rear1) %max;

}

}

输入队列(队列队列) {

int t;

if(queue.front==queue.rear ) {

printf (“排队失败。 排队是空的。 n "

返回- 1;

}

t=queue.base[queue.front];

queue.front=(queue.front1) %max;

返回t;

}

int main () )。

队列队列;

初始堆栈(队列);

int n;

printf (“输入数据数:(n )”);

scanf('%d ',n );

printf (“请输入数据。 n "

for(intI=0; I

int e;

扫描(' % d ',e );

推送(队列,e );

}

while(queue.front!=queue.rear ) {

printf('%d ',pop ) ) queue );

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。