#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 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){
printf("キューが満杯なので入りませんでした。\n"); }else{
queue[tail++]=value;
}
tail=tail%SIZE;
}
int dequeue(void)
{
int value;
if(head==tail){
printf("キューは空なので取り出せませんでした。"); }else{
value=queue[head];
queue[head]=0;
head++;
}
head=head%SIZE;
return value;
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBxdWV1ZVtTSVpFXTsKaW50IGhlYWQsIHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBoZWFkID0gdGFpbCA9IDA7IAogICAgaW50ICBpOwoKICAgIGVucXVldWUoMSk7CiAgICBlbnF1ZXVlKDIpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSgzKTsKICAgIGRlcXVldWUoKTsKICAgIGVucXVldWUoNCk7CiAgICBlbnF1ZXVlKDUpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSg2KTsKCiAgICBmb3IoaT0wOyBpPFNJWkU7IGkrKyl7CiAgICAgIHByaW50ZigicXVldWVbJWRdPSVkXG4iLCBpLCBxdWV1ZVtpXSApOwogICAgfQoKICAgIHJldHVybiAwOwp9Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKQp7CglpZihoZWFkPT0odGFpbCsxKSVTSVpFKXsKCQlwcmludGYoIuOCreODpeODvOOBjOa6gOadr+OBquOBruOBp+WFpeOCiuOBvuOBm+OCk+OBp+OBl+OBn+OAglxuIik7Cgl9ZWxzZXsK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