#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 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+1;
}
tail=tail%SIZE;
}
int dequeue(void)
{
int value;
if(head==tail){
return 0;
}else{
value=queue[head];
queue[head]=0;
head=head+1;
}
head=head%SIZE;
return value;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIFNJWkUgNQppbnQgcXVldWVbU0laRV07CmludCBoZWFkLHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKSAKewoJaGVhZD10YWlsPTA7CglpbnQgaTsKCQoJZW5xdWV1ZSgxKTsKCWVucXVldWUoMik7CglkZXF1ZXVlKCk7CgllbnF1ZXVlKDMpOwoJZGVxdWV1ZSgpOwoJZW5xdWV1ZSg0KTsKCWVucXVldWUoNSk7CglkZXF1ZXVlKCk7CgllbnF1ZXVlKDYpOwoJCglmb3IoaT0wOyBpPFNJWkU7aSsrKXsKCQlwcmludGYoInF1ZXVlWyVkXT0lZFxuIixpLHF1ZXVlW2ldKTsKCX0KCQoJcmV0dXJuIDA7Cn0KCgp2b2lkIGVucXVldWUoaW50IHZhbHVlKQp7CglpZihoZWFkPT0odGFpbCsxKSVTSVpFKXsKCQlwcmludGYoIuOCreODpeODvOOBr+a6gOW4huOBp+WFpeOCiuOBvuOBm+OCk+OBp+OBl+OBn1xuIik7Cgl9ZWxzZXsKCQlxdWV1ZVt0YWlsXT12YWx1ZTsKCQl0YWlsPXRhaWwrMTsKCX0KCXRhaWw9dGFpbCVTSVpFOwp9CgppbnQgZGVx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