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