#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();
enqueue(6);
for(i=0; i<SIZE; i++){
printf("queue[%d]=%d\n", i
, queue
[i
] ); }
return 0;
}
void enqueue(int value)
{
if ((tail + 1) % SIZE == head) {
return;
}
queue[tail] = value;
tail = (tail + 1) % SIZE;
}
int dequeue(void)
{
int value;
if (head == tail) {
return -1;
}
value = queue[head];
queue[head] = 0;
head = (head + 1) % SIZE;
return value;
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBxdWV1ZVtTSVpFXTsKaW50IGhlYWQsIHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBoZWFkID0gdGFpbCA9IDA7IAogICAgaW50IGRhdGEsIGk7CgogICAgZW5xdWV1ZSgxKTsKICAgIGVucXVldWUoMik7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDMpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSg0KTsKICAgIGVucXVldWUoNSk7CiAgICBkZXF1ZXVlKCk7CiAgICBlbnF1ZXVlKDYpOwogICAgZm9yKGk9MDsgaTxTSVpFOyBpKyspewogICAgICBwcmludGYoInF1ZXVlWyVkXT0lZFxuIiwgaSwgcXVldWVbaV0gKTsKICAgIH0KICAgIHJldHVybiAwOwp9CnZvaWQgZW5xdWV1ZShpbnQgdmFsdWUpCnsKICAgIGlmICgodGFpbCArIDEpICUgU0laRSA9PSBoZWFkKSB7CiAgICAgICAgcHJpbnRmKCLjgq3jg6Xjg7zjga/muoDmna/jgafjgZlcbiIpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIHF1ZXVlW3RhaWxdID0gdmFsdWU7CiAgICB0YWlsID0gKHRhaWwgKyAxKSAlIFNJWkU7Cn0KaW50IGRlcXVldWUodm9pZCkKewoJaW50IHZhbHVlOwogICAgaWYgKGhlYWQgPT0gdGFpbCkgewogICAgICAgIHByaW50Zigi44Kt44Ol44O844Gv56m644Gn44GZXG4iKTsKICAgICAgICByZXR1cm4gLTE7CiAgICB9CiAgICB2YWx1ZSA9IHF1ZXVlW2hlYWRdOwogICAgcXVldWVbaGVhZF0gPSAwOwogICAgaGVhZCA9IChoZWFkICsgMSkgJSBTSVpFOwogICAgcmV0dXJuIHZhbHVlOwp9