#include <stdio.h>
#define SIZE 5
int queue[SIZE];
int head,tail;
void enqueu(int value);
int dequeu(void);
int main(void) {
head=tail=0;
int i;
enqueu(1);
enqueu(2);
dequeu();
enqueu(3);
dequeu();
enqueu(4);
enqueu(5);
dequeu();
enqueu(6);
for(i=0; i<SIZE; i++){
printf("queue[%d]=%d\n", i
, queue
[i
] ); }
return 0;
}
void enqueu(int value){
if(tail
+1==head
) printf("満タン"); else{
queue[tail]=value;
tail++;
tail=tail%SIZE;
}
}
int dequeu(void){
int value;
if(tail==head) {
return 0;}
else{
value=queue[head];
queue[head]=0;
head++;
head=head%SIZE;
return value;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIFNJWkUgNQppbnQgcXVldWVbU0laRV07CmludCBoZWFkLHRhaWw7Cgp2b2lkIGVucXVldShpbnQgdmFsdWUpOwppbnQgZGVxdWV1KHZvaWQpOwoKaW50IG1haW4odm9pZCkgewoJCgloZWFkPXRhaWw9MDsKCWludCBpOwoJZW5xdWV1KDEpOwoJZW5xdWV1KDIpOwoJZGVxdWV1KCk7CgllbnF1ZXUoMyk7CglkZXF1ZXUoKTsKCWVucXVldSg0KTsKCWVucXVldSg1KTsKCWRlcXVldSgpOwoJZW5xdWV1KDYpOwoJCgkgZm9yKGk9MDsgaTxTSVpFOyBpKyspewogICAgICBwcmludGYoInF1ZXVlWyVkXT0lZFxuIiwgaSwgcXVldWVbaV0gKTsKICAgIH0KCQoJcmV0dXJuIDA7Cn0KCnZvaWQgZW5xdWV1KGludCB2YWx1ZSl7CgkKCWlmKHRhaWwrMT09aGVhZCkgcHJpbnRmKCLmuoDjgr/jg7MiKTsKCWVsc2V7CgkJcXVldWVbdGFpbF09dmFsdWU7CgkJdGFpbCsrOwoJCXRhaWw9dGFpbCVTSVpFOwoJfQp9CmludCBkZXF1ZXUodm9pZCl7CglpbnQgdmFsdWU7CglpZih0YWlsPT1oZWFkKSB7CgkJcHJpbnRmKCLnqboiKTsKCQlyZXR1cm4gMDt9CgllbHNlewoJCXZhbHVlPXF1ZXVlW2hlYWRdOwoJCXF1ZXVlW2hlYWRdPTA7CgkJaGVhZCsrOwoJCWhlYWQ9aGVhZCVTSVpFOwoJCXJldHVybiB2YWx1ZTsKCX0KfQ==