#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( head == (tail+1)%SIZE ){
}else{
queue[tail] = value;
tail = tail + 1;
}
tail = tail % SIZE;
}
int dequeue(void)
{int value;
if( head == tail ){
return 0;
}else{
value = queue[head];
queue[head] = 0; //抽出後に0を代入
head = head + 1;
}
head = head % SIZE;
return value;
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBxdWV1ZVtTSVpFXTsKaW50IGhlYWQsIHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBoZWFkID0gdGFpbCA9IDA7IAogICAgaW50IGRhdGEsIGk7CgogICAgZW5xdWV1ZSgxKTsKICAgIGVucXVldWUoMik7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDMpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSg0KTsKICAgIGVucXVldWUoNSk7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDYpOwoKICAgIGZvcihpPTA7IGk8U0laRTsgaSsrKXsKICAgICAgcHJpbnRmKCJxdWV1ZVslZF09JWRcbiIsIGksIHF1ZXVlW2ldICk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0KCnZvaWQgZW5xdWV1ZShpbnQgdmFsdWUpCntpZiggaGVhZCA9PSAodGFpbCsxKSVTSVpFICl7CiAgICAgICAgcHJpbnRmKCLjgq3jg6Xjg7zjga/muoDmna/jgaflhaXjgorjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwogICAgfWVsc2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