#include <stdio.h>
#define SIZE 5
int queue[SIZE];
int head, tail;
void enqueue(int value);
int dequeue(void);
int main(void) {
head = tail = 0;
int data, i;
enqueue(1);
enqueue(2);
dequeue();
enqueue(3);
dequeue();
enqueue(4);
enqueue(5);
dequeue();
enqueue(6);
for (i = 0; i < SIZE; i++) {
printf("queue[%d]=%d\n", i
, queue
[i
]); }
return 0;
}
void enqueue(int value) {
if((tail+1)%SIZE==head){
}
else{
queue[tail]=value;//新しい場所を格納
tail=(tail+1)%SIZE;//tailを次の場所に進める
}
}
int dequeue(void) {
if(head==tail){
return 0; //エラーだから0を返してあげる
}
else{
int value;
value=queue[head];//headから数値を取り出し、保存する
queue[head]=0; //抽出した場所を0で初期化
head=(head+1)%SIZE; //headを次に進める
return value;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgU0laRSA1CgppbnQgcXVldWVbU0laRV07CmludCBoZWFkLCB0YWlsOwoKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSk7CmludCBkZXF1ZXVlKHZvaWQpOwoKCmludCBtYWluKHZvaWQpIHsKICAgIGhlYWQgPSB0YWlsID0gMDsKICAgIGludCBkYXRhLCBpOwogICAgZW5xdWV1ZSgxKTsKICAgIGVucXVldWUoMik7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDMpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSg0KTsKICAgIGVucXVldWUoNSk7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDYpOwogICAgZm9yIChpID0gMDsgaSA8IFNJWkU7IGkrKykgewogICAgICAgIHByaW50ZigicXVldWVbJWRdPSVkXG4iLCBpLCBxdWV1ZVtpXSk7CiAgICB9CiAgICByZXR1cm4gMDsKfQoKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSkgewoJaWYoKHRhaWwrMSklU0laRT09aGVhZCl7CgkJcHJpbnRmKCLjgq3jg6Xjg7zjga/muoDmna/jgaDjgohcbiIpOw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