Untitled
unknown
plain_text
2 years ago
2.5 kB
7
Indexable
int main() {
Queue fast,normal;
Element element;
char comando;
char basura;
fast = QUEUE_create();
normal = QUEUE_create();
/*
F -> Fast
N -> Normal
A -> Enter attraction
Q -> Quit
*/
do {
scanf("%c",&comando); //Solo roba hasta el ' ' o el '\n'
scanf("%c",&basura); //Roba el espacio o el salto de linea
switch(comando) {
case 'F':
scanf("%d",&element.size);
scanf("%c",&basura);
scanf("%s",element.name);
scanf("%c",&basura);
if(!QUEUE_isFull(fast)) {
QUEUE_add(&fast,element);
printf("%s (%d) has been added to the Fast queue.\n",element.name,element.size);
}else {
printf("The Fast queue is full.\n");
}
break;
case 'N':
scanf("%d",&element.size);
scanf("%c",&basura);
scanf("%s",element.name);
scanf("%c",&basura);
if(!QUEUE_isFull(normal)) {
QUEUE_add(&normal,element);
printf("%s (%d) has been added to the Normal queue.\n",element.name,element.size);
}else {
printf("The Fast queue is full.\n");
}
break;
case 'A':
if(QUEUE_isEmpty(fast) && QUEUE_isEmpty(normal)) {
printf("No group is available yet.\n");
} else {
if(!QUEUE_isEmpty(fast)) {
element = QUEUE_getFirst(&fast);
printf("%s (%d) has entered the attraction.\n",element.name,element.size);
QUEUE_remove(&fast);
} else {
if(!QUEUE_isEmpty(normal)) {
element = QUEUE_getFirst(&normal);
printf("%s (%d) has entered the attraction.\n",element.name,element.size);
QUEUE_remove(&normal);
}
}
}
break;
case 'Q':
QUEUE_destroy(&fast);
QUEUE_destroy(&normal);
printf("See you soon!\n");
break;
}
}while(comando != 'Q');
return 0;
}Editor is loading...