#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;
enqueue(1);
enqueue(2);
dequeue();
enqueue(3);
dequeue();
enqueue(4);
enqueue(5);
dequeue();
enqueue(6);
for(int 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 % SIZE;
}
int dequeue(void)
{
int value;
if( head == tail ){
return 0;
}else{
queue[head]=0;
value = queue[head++];
}
head = head % SIZE;
return value;
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBxdWV1ZVtTSVpFXTsKaW50IGhlYWQsIHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBoZWFkID0gdGFpbCA9IDA7CiAgICBpbnQgZGF0YTsKCiAgICBlbnF1ZXVlKDEpOwogICAgZW5xdWV1ZSgyKTsKICAgIGRlcXVldWUoKTsKICAgIGVucXVldWUoMyk7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDQpOwogICAgZW5xdWV1ZSg1KTsKICAgIGRlcXVldWUoKTsKICAgIGVucXVldWUoNik7CgogICAgZm9yKGludCBpPTA7IGk8U0laRTsgaSsrKXsKICAgICAgICBwcmludGYoInF1ZXVlWyVkXT0lZFxuIiwgaSwgcXVldWVbaV0pOwogICAgfQoKICAgIHJldHVybiAwOwp9Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKQp7CiAgICBpZiggaGVhZCA9PSAodGFpbCsxKSVTSVpFICl7CiAgICAgICAgcHJpbnRmKCLjgq3jg6Xjg7zjga/muoDmna/jgaflhaXjgorjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwogICAgfWVsc2V7CiAgICAgICAgcXVldWVbdGFpbCsrXS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