#include<stdio.h>
#define Queue_size 10
int Queue[Queue_size];
int in,out;
int count;
void initialze() {
in = 0; out = 0; count =0;
}
void enterq(int val) {
if(count<Queue_size ){
in++;
if(in==Queue_size) in =0;
count++;
Queue[in] = val;
}else printf("Queue full\n");
}
int removeq(void) {
if(count>0) {
out++;
if(out==Queue_size) out =0;
count--;
return Queue[out];
}else {
printf("Queue empty\n");
return -1;
}
}
void display(void) {
int i;
for(i=1;i<=Queue_size;i++){
printf("\n%d\n",Queue[i]);
if(count == i) break;
}
}
main() {
int mode,id;
initialze();
mode = 1;
while(mode) {
printf("queue process ? enter(1) or remove(0) ="); scanf("%d",&mode);
if(mode==1) {
printf("? id = "); scanf("%d",&id);
enterq(id);
}else if(mode==0) {
id = removeq();
if(id>0) printf("id = %d was removed\n",id);
}
display();
printf("?continue(1) or quit(0) = "); scanf("%d",&mode);
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2RlZmluZSBRdWV1ZV9zaXplIDEwCgppbnQgUXVldWVbUXVldWVfc2l6ZV07CmludCBpbixvdXQ7CmludCBjb3VudDsKdm9pZCBpbml0aWFsemUoKSB7CiAgICBpbiA9IDA7IG91dCA9IDA7IGNvdW50ID0wOwp9CnZvaWQgZW50ZXJxKGludCB2YWwpIHsKICAgIGlmKGNvdW50PFF1ZXVlX3NpemUgKXsKICAgICAgICBpbisrOwogICAgICAgIGlmKGluPT1RdWV1ZV9zaXplKSBpbiA9MDsKICAgICAgICBjb3VudCsrOwogICAgICAgIFF1ZXVlW2luXSA9IHZhbDsKICAgIH1lbHNlIHByaW50ZigiUXVldWUgZnVsbFxuIik7Cn0KaW50IHJlbW92ZXEodm9pZCkgewogICAgaWYoY291bnQ+MCkgewogICAgICAgIG91dCsrOwogICAgICAgIGlmKG91dD09UXVldWVfc2l6ZSkgb3V0ID0wOwogICAgICAgIGNvdW50LS07CiAgICAgICAgcmV0dXJuIFF1ZXVlW291dF07CiAgICB9ZWxzZSB7CiAgICAgICAgcHJpbnRmKCJRdWV1ZSBlbXB0eVxuIik7CiAgICAgICAgcmV0dXJuIC0xOwogICAgfQp9CnZvaWQgZGlzcGxheSh2b2lkKSB7CiAgICBpbnQgaTsKICAgIGZvcihpPTE7aTw9UXVldWVfc2l6ZTtpKyspewogICAgICAgIHByaW50ZigiXG4lZFxuIixRdWV1ZVtpXSk7CiAgICAgICAgaWYoY291bnQgPT0gaSkgYnJlYWs7CiAgICB9Cn0KCiBtYWluKCkgewogICAgaW50IG1vZGUsaWQ7CiAgICBpbml0aWFsemUoKTsKICAgIG1vZGUgPSAxOwogICAgd2hpbGUobW9kZSkgewogICAgICAgIHByaW50ZigicXVldWUgcHJvY2VzcyA/IGVudGVyKDEpIG9yICByZW1vdmUoMCkgPSIpOyBzY2FuZigiJWQiLCZtb2RlKTsKICAgICAgICBpZihtb2RlPT0xKSB7CiAgICAgICAgICAgIHByaW50ZigiPyBpZCA9ICIpOyBzY2FuZigiJWQiLCZpZCk7CiAgICAgICAgICAgIGVudGVycShpZCk7CiAgICAgICAgfWVsc2UgaWYobW9kZT09MCkgewogICAgICAgICAgICBpZCA9IHJlbW92ZXEoKTsKICAgICAgICAgICAgaWYoaWQ+MCkgcHJpbnRmKCJpZCA9ICVkIHdhcyByZW1vdmVkXG4iLGlkKTsKICAgICAgICB9CiAgICAgICAgZGlzcGxheSgpOwogICAgICAgIHByaW50ZigiP2NvbnRpbnVlKDEpIG9yIHF1aXQoMCkgPSAiKTsgc2NhbmYoIiVkIiwmbW9kZSk7CiAgICB9CiAgICByZXR1cm4gMDsKfQoK