#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;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2RlZmluZSBTSVpFIDUKaW50IHF1ZXVlW1NJWkVdOwppbnQgaGVhZCwgdGFpbDsKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSk7CmludCBkZXF1ZXVlKHZvaWQpOwppbnQgbWFpbih2b2lkKQp7CiBoZWFkID0gdGFpbCA9IDA7IC8v5Yid5pyf5YyWCiBpbnQgZGF0YSwgaTsKIGVucXVldWUoMSk7CiBlbnF1ZXVlKDIpOwogZGVxdWV1ZSgpOwogZW5xdWV1ZSgzKTsKIGRlcXVldWUoKTsKIGVucXVldWUoNCk7CiBlbnF1ZXVlKDUpOwogZGVxdWV1ZSgpOwogZm9yKGk9MDsgaTxTSVpFOyBpKyspewogcHJpbnRmKCJxdWV1ZVslZF09JWTCpW4iLCBpLCBxdWV1ZVtpXSApOwogfQogcmV0dXJuIDA7Cn0Kdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSkKewogaWYoIGhlYWQgPT0gKHRhaWwrMSklU0laRSApewogcHJpbnRmKCLjgq3jg6Xjg7zjga/muoDmna/jgaflhaXjgorjgb7jgZvjgpPjgafjgZfjgZ/CpW4iKTsKIH1lbHNlewogcXVldWVbdGFpbF0gPSB2YWx1ZTsKIHRhaWwgPSB0YWlsICsgMTsKIH0KIHR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