#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);
enqueue(7);
enqueue(8);
for(i=0; i<SIZE; i++){
printf("queue[%d]=%d\n", i
, queue
[i
] ); }
return 0;
}
void enqueue(int value)
{
if(head==(tail+1)%SIZE){
}else{
queue[tail++]=value;
}
tail=tail%SIZE;
}
int dequeue(void)
{
int value;
if(head==tail){
printf("キューは空で取り出せませんでした。\n"); return 0;
}else{
value=queue[head];
}
queue[head]=0;
head=(head+1)%SIZE;
return value;
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBxdWV1ZVtTSVpFXTsKaW50IGhlYWQsIHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBoZWFkID0gdGFpbCA9IDA7IAogICAgaW50IGRhdGEsIGk7CgogICAgZW5xdWV1ZSgxKTsKICAgIGVucXVldWUoMik7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDMpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSg0KTsKICAgIGVucXVldWUoNSk7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDYpOwogICAgZW5xdWV1ZSg3KTsKICAgIGVucXVldWUoOCk7CgogICAgZm9yKGk9MDsgaTxTSVpFOyBpKyspewogICAgICBwcmludGYoInF1ZXVlWyVkXT0lZFxuIiwgaSwgcXVldWVbaV0gKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQoKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSkKewogICBpZihoZWFkPT0odGFpbCsxKSVTSVpFKXsKICAgCXByaW50Zigi44Kt44Ol44O844Gv5rqA5p2v44Gn5YWl44KK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