#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 date,i;
enqueue(1);
enqueue(2);
dequeue();
enqueue(3);
dequeue();
enqueue(4);
enqueue(5);
dequeue();
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+CiNkZWZpbmUgU0laRSA1CmludCBxdWV1ZVtTSVpFXTsKaW50IGhlYWQsdGFpbDsKCnZvaWQgZW5xdWV1ZShpbnQgdmFsdWUpOwppbnQgZGVxdWV1ZSh2b2lkKTsKCmludCBtYWluKHZvaWQpIHsKCWhlYWQ9dGFpbD0wOwoJaW50IGRhdGUsaTsKCQoJZW5xdWV1ZSgxKTsKCWVucXVldWUoMik7CglkZXF1ZXVlKCk7CgllbnF1ZXVlKDMpOwoJZGVxdWV1ZSgpOwoJZW5xdWV1ZSg0KTsKCWVucXVldWUoNSk7CglkZXF1ZXVlKCk7CgkKCWZvcihpPTA7aTxTSVpFO2krKyl7CgkJcHJpbnRmKCJxdWV1ZVslZF09JWRcbiIsaSxxdWV1ZVtpXSk7Cgl9CglyZXR1cm4gMDsKfQoKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSl7CglpZihoZWFkPT0odGFpbCsxKSVTSVpFKXsKCQlwcmludGYoIuOCreODpeODvOOBr+a6gOadr+OBp+OBr+OBhOOCiuOBvuOBm+OCk+OBp+OBl+OBn1xuIik7Cgl9CgllbHNlewoJCXF1ZXVlW3RhaWxdPXZhbHVlOwoJCXRhaWw9dGFpbCsxOwoJfQoJdGFpbD10YWlsJVNJWkU7Cn0KCmludCBkZXF1ZXVlKHZvaW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