#include <stdio.h>
#define SIZE 5
int queue[5];
int head,tail;
void enqueue(int value);
int dequeue(void);
int main(void){
head=tail=0;
int resp,data,i;
while(1){
if(!resp)
break;
switch(resp){
case 1: scanf("%d",&data
); enqueue(data);
break;
case 2: dequeue();
}
printf("head=%d tail=%d\n",head
,tail
); }
//printf("\n");
i=head;
while(i!=tail){
printf("queue[%d]=%d \n",i
,queue
[i
]); i++;
i=i%SIZE;
}
return 0;
}
void enqueue(int value){
if(head==tail+1){
}else{
queue[tail++]=value;
}
tail=tail%SIZE;
}
int dequeue(void){
int value;
if(head==tail){
return 0;
}else{
value=queue[head++];
}
head=head%SIZE;
return value;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIFNJWkUgNQppbnQgcXVldWVbNV07CmludCBoZWFkLHRhaWw7Cgp2b2lkIGVucXVldWUoaW50IHZhbHVlKTsKaW50IGRlcXVldWUodm9pZCk7CgppbnQgbWFpbih2b2lkKXsKCWhlYWQ9dGFpbD0wOwoJaW50IHJlc3AsZGF0YSxpOwoJCgl3aGlsZSgxKXsKCQlzY2FuZigiJWQiLCZyZXNwKTsKCQlpZighcmVzcCkKCQlicmVhazsKCQkKCQlzd2l0Y2gocmVzcCl7CgkJCWNhc2UgMTogc2NhbmYoIiVkIiwmZGF0YSk7CgkJCSAgICAgICBlbnF1ZXVlKGRhdGEpOwoJCQkgICAgICAgYnJlYWs7CgkJCWNhc2UgMjogZGVxdWV1ZSgpOwoJCX0KCQlwcmludGYoImhlYWQ9JWQgdGFpbD0lZFxuIixoZWFkLHRhaWwpOwoJfQoJLy9wcmludGYoIlxuIik7Cmk9aGVhZDsKd2hpbGUoaSE9dGFpbCl7CglwcmludGYoInF1ZXVlWyVkXT0lZCBcbiIsaSxxdWV1ZVtpXSk7CglpKys7CglpPWklU0laRTsKfQpyZXR1cm4gMDsKfQoKdm9pZCBlbnF1ZXVlKGludCB2YWx1ZSl7CglpZihoZWFkPT10YWlsKzEpewoJCXByaW50Zigi44Kt44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