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