#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();
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;
}
I2luY2x1ZGU8c3RkaW8uaD4gCiAKI2RlZmluZSBTSVpFIDUgCmludCBxdWV1ZVtTSVpFXTsgCmludCBoZWFkLCB0YWlsOyAKIAp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsgCmludCBkZXF1ZXVlKHZvaWQpOyAKIAppbnQgbWFpbih2b2lkKSAKeyAKICAgIGhlYWQgPSB0YWlsID0gMDsgICAgLy/liJ3mnJ/ljJYgCiAgICBpbnQgZGF0YSwgaTsgCiAKICAgIGVucXVldWUoMSk7IAogICAgZW5xdWV1ZSgyKTsgCiAgICBkZXF1ZXVlKCk7IAogICAgZW5xdWV1ZSgzKTsgCiAgICBkZXF1ZXVlKCk7IAogICAgZW5xdWV1ZSg0KTsgCiAgICBlbnF1ZXVlKDUpOyAKICAgIGRlcXVldWUoKTsgCiAgICBmb3IoaT0wOyBpPFNJWkU7IGkrKyl7IAogICAgICBwcmludGYoInF1ZXVlWyVkXT0lZMKlbiIsIGksIHF1ZXVlW2ldICk7IAogICAgfSAKIAogICAgcmV0dXJuIDA7IAp9IAogCnZvaWQgZW5xdWV1ZShpbnQgdmFsdWUpIAp7IAogICAgaWYoIGhlYWQgPT0gKHRhaWwrMSklU0laRSApeyAKICAgICAgICBwcmludGYoIuOCreODpeODvOOBr+a6gOadr+OBp+WFpeOC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