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