关注公众号程序猿从入门到入土查询更方便哦
【8565】变成,采用顺序村春实现循环队列的初始化,入队,出队操作。要求输入整形数据,输入0表示结束(0不存储在栈中)
输入
1 2 3 4 5 6 7 8 9 0
输出
1 2 3 4 5 6 7 8 9 0
#include<bits/stdc++.h>
using namespace std;
typedef struct CircleQueue {
int first;
int rear;
int data[100];
}CQueue;
void InitQueue(CQueue& Q) {
Q.first = Q.rear = 0;
}
void InQueue(CQueue& Q, int data) {
Q.data[Q.rear] = data;
Q.rear++;
}
int OutQueue(CQueue& Q) {
int temp;
temp = Q.data[Q.first];
Q.first++;
return temp;
}
int main() {
CQueue Q;
InitQueue(Q);
int n;
cin >> n;
while (n != 0) {
InQueue(Q, n);
cin >> n;
}
while ((Q.rear-Q.first+1000)%1000>0) {
cout << OutQueue(Q)<<" ";
}
return 0;
}