Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------*/
- /*| FILAS.C |*/
- /*----------------------*/
- #include <stdio.h> /* I/O */
- #include <stdlib.h> /* malloc*/
- #include <stdbool.h> /*bool*/
- #include <time.h> /* rand && srand() */
- #include <unistd.h>
- #define MAX_PISTAS 4
- #define MAX_PRATELEIRAS 3
- typedef struct Queue
- {
- int pistas,prateleiras;
- struct Queue *begin,*end;
- }queue;
- int len=0;
- int random_id()
- {
- srand(time(NULL));
- return rand () % 100;
- }
- queue *queue_create(void)
- {
- queue *q = (queue *) malloc(sizeof(queue));
- if (q!= NULL)
- q->begin = NULL;
- q->end = NULL;
- return q;
- }
- bool isEmpty(queue **q)
- {
- return ()
- }
- queue *enfileirar(queue **q,int IDaviao)
- {
- queue *novo = (queue *) malloc(sizeof(queue)); /*alocando memoria dinamicamente */
- int y,i,t_clock,r;
- if (novo == NULL) /* se ocorrer algum erro de alocacao */
- {
- fprintf(stderr,"erro de alocacao\n");
- exit( 1 );
- }
- srand(time(NULL));
- r = rand()%4;
- for(t_clock =r; t_clock >=0; t_clock--){
- sleep( 1 );
- printf("\n\tTempo Para aterrisagem: { 00 : 0%d } \n",t_clock);
- if (t_clock == 0)
- {
- if (r == 1 || r == 2 || r == 3 || r==4)
- {
- if (novo != NULL)
- novo->begin = NULL;
- novo->pistas = IDaviao;
- novo->end =(*q);
- if ((*q)->end == NULL)
- {
- printf("\nVAZIA\n");
- (*q)->begin = novo;
- }else
- {
- printf("\nTEM\n");
- queue *aux;
- aux = (*q)->begin;
- for(; aux != NULL; aux=aux->begin)
- (*q)->end = novo;
- }
- }else if (r ==0)
- {
- printf("\nAVIAO CAIU: %d \n",IDaviao);
- len--;
- }
- }
- }
- len++;
- if (len > MAX_PISTAS)
- printf("\nFilas Excedidas \n");
- return novo;
- }
- void show(queue **q)
- {
- int i=0;
- for(; i <len; i++)
- printf("PISTA [%d] -> ID: %d \n",i,(*q)->pistas);
- }
- int main()
- {
- queue *q = queue_create();
- int id,opc;
- if(q!= NULL)
- for(;;){
- id = random_id();
- printf("\n\t-> id [ %d ] \n",id);
- printf("\n\t_(0)---------- [SAIR]");
- printf("\n\t_(1)---------- [ PUSH ]");
- printf("\n\t_(2)---------- [ SHOW ] \n");
- printf("\t> "); scanf("%d",&opc);
- switch(opc){
- case 0:
- exit( 0 );
- default:
- break;
- case 1:
- q=enfileirar(&q,id);
- break;
- case 2:
- show(&q);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement