c语言实现循环队列,循环队列Q最多可存储
#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 );
}
}