#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;
}
int removeq(void) {
if(count>0) {
out++;
if(out==Queue_size) out =0;
count--;
return Queue[out];
}else {
return -1;
}
}
void display(void) {
int i;
for(i=1;i<=Queue_size;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) {
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;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2RlZmluZSBRdWV1ZV9zaXplIDEwCiAKaW50IFF1ZXVlW1F1ZXVlX3NpemVdOwppbnQgaW4sb3V0OwppbnQgY291bnQ7CnZvaWQgaW5pdGlhbHplKCkgewogICAgaW4gPSAwOyBvdXQgPSAwOyBjb3VudCA9MDsKfQp2b2lkIGVudGVycShpbnQgdmFsKSB7CiAgICBpZihjb3VudDxRdWV1ZV9zaXplICl7CiAgICAgICAgaW4rKzsKICAgICAgICBpZihpbj09UXVldWVfc2l6ZSkgaW4gPTA7CiAgICAgICAgY291bnQrKzsKICAgICAgICBRdWV1ZVtpbl0gPSB2YWw7CiAgICB9ZWxzZSBwcmludGYoIlF1ZXVlIGZ1bGxcbiIpOwp9CmludCByZW1vdmVxKHZvaWQpIHsKICAgIGlmKGNvdW50PjApIHsKICAgICAgICBvdXQrKzsKICAgICAgICBpZihvdXQ9PVF1ZXVlX3NpemUpIG91dCA9MDsKICAgICAgICBjb3VudC0tOwogICAgICAgIHJldHVybiBRdWV1ZVtvdXRdOwogICAgfWVsc2UgewogICAgICAgIHByaW50ZigiUXVldWUgZW1wdHlcbiIpOwogICAgICAgIHJldHVybiAtMTsKICAgIH0KfQp2b2lkIGRpc3BsYXkodm9pZCkgewogICAgaW50IGk7CiAgICBmb3IoaT0xO2k8PVF1ZXVlX3NpemU7aSsrKXsKICAgICAgICBwcmludGYoIlxuJWRcbiIsUXVldWVbaV0pOwogICAgICAgIGlmKGNvdW50ID09IGkpIGJyZWFrOwogICAgfQp9CiAKIG1haW4oKSB7CiAgICBpbnQgbW9kZSxpZDsKICAgIGluaXRpYWx6ZSgpOwogICAgbW9kZSA9IDE7CiAgICB3aGlsZShtb2RlKSB7CiAgICAgICAgcHJpbnRmKCJxdWV1ZSBwcm9jZXNzID8gZW50ZXIoMSkgb3IgIHJlbW92ZSgwKSA9Iik7IHNjYW5mKCIlZCIsJm1vZGUpOwogICAgICAgIGlmKG1vZGU9PTEpIHsKICAgICAgICAgICAgcHJpbnRmKCI/IGlkID0gIik7IHNjYW5mKCIlZCIsJmlkKTsKICAgICAgICAgICAgZW50ZXJxKGlkKTsKICAgICAgICB9ZWxzZSBpZihtb2RlPT0wKSB7CiAgICAgICAgICAgIGlkID0gcmVtb3ZlcSgpOwogICAgICAgICAgICBpZihpZD4wKSBwcmludGYoImlkID0gJWQgd2FzIHJlbW92ZWRcbiIsaWQpOwogICAgICAgIH0KICAgICAgICBkaXNwbGF5KCk7CiAgICAgICAgcHJpbnRmKCI/Y29udGludWUoMSkgb3IgcXVpdCgwKSA9ICIpOyBzY2FuZigiJWQiLCZtb2RlKTsKICAgIH0KICAgIHJldHVybiAwOwp9CiAK