#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) {
} else {
queue[tail] = value;
tail = (tail + 1) % SIZE;
}
}
int dequeue(void)
{
int value;
if (head == tail) {
return 0;
} else {
value = queue[head];
head = (head + 1) % SIZE;
return value;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiAKI2RlZmluZSBTSVpFIDUKaW50IHF1ZXVlW1NJWkVdOwppbnQgaGVhZCwgdGFpbDsKIAp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CiAKaW50IG1haW4odm9pZCkgewogICAgaGVhZCA9IHRhaWwgPSAwOwogICAgaW50IGRhdGEsIGk7CiAKICAgIGVucXVldWUoMSk7CiAgICBlbnF1ZXVlKDIpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSgzKTsKICAgIGRlcXVldWUoKTsKICAgIGVucXVldWUoNCk7CiAgICBlbnF1ZXVlKDUpOwogICAgZGVxdWV1ZSgpOwogICAgZW5xdWV1ZSg2KTsKIAogICAgZm9yIChpID0gMDsgaSA8IFNJWkU7IGkrKykgewogICAgICAgIHByaW50ZigicXVldWVbJWRdPSVkXG4iLCBpLCBxdWV1ZVtpXSk7CiAgICB9CiAKICAgIHJldHVybiAwOwp9CiAKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSkKewogICAgaWYgKCgodGFpbCArIDEpICUgU0laRSkgPT0gaGVhZCkgewogICAgICAgIHByaW50Zigi44Kt44Ol44O844Gv5rqA5p2v44Gn5YWl44KK44G+44Gb44KT44Gn44GX44GfXG4iKTsKICAgIH0gZWxzZSB7CiAgIC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