#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;
}
I2luY2x1ZGU8c3RkaW8uaD4gCiNkZWZpbmUgU0laRSA1IAppbnQgcXVldWVbU0laRV07IAppbnQgaGVhZCwgdGFpbDsgCnZvaWQgZW5xdWV1ZShpbnQgdmFsdWUpOyAKaW50IGRlcXVldWUodm9pZCk7IAppbnQgbWFpbih2b2lkKSAKeyAKIGhlYWQgPSB0YWlsID0gMDsgLy/liJ3mnJ/ljJYKIGludCBkYXRhLCBpOyAKIGVucXVldWUoMSk7IAogZW5xdWV1ZSgyKTsgCiBkZXF1ZXVlKCk7IAogZW5xdWV1ZSgzKTsgCiBkZXF1ZXVlKCk7IAogZW5xdWV1ZSg0KTsgCiBlbnF1ZXVlKDUpOyAKIGRlcXVldWUoKTsgCiBmb3IoaT0wOyBpPFNJWkU7IGkrKyl7IAogcHJpbnRmKCJxdWV1ZVslZF09JWRcbiIsIGksIHF1ZXVlW2ldICk7IAogfSAKIHJldHVybiAwOyAKfSAKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSkgCnsgCiBpZiggaGVhZCA9PSAodGFpbCsxKSVTSVpFICl7IAogcHJpbnRmKCLjgq3jg6Xjg7zjga/muoDmna/jgaflhaXjgorjgb7jgZvjgpPjgafjgZfjgZ/CpW4iKTsgCiB9ZWxzZXsgCiBxdWV1ZVt0YWlsXSA9IHZhb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