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>
- #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;
- }
- queue *enfileirar(queue **q,int IDaviao)
- {
- queue *novo = (queue *) malloc(sizeof(queue)); /*alocando memoria dinamicamente */
- if (novo == NULL) /* se ocorrer algum erro de alocacao */
- {
- fprintf(stderr,"erro de alocaca\n");
- exit( 1 );
- }
- 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");
- (*q)->end = novo;
- }
- len++;
- if (len ==3)
- printf("\nFILA EXcedida \n");
- return novo;
- }
- void show(queue **q)
- {
- int i=0;
- for(; i <1; i++)
- printf("[ %d ] \n",(*q)->pistas);
- }
- int main()
- {
- queue *q = queue_create();
- int id;
- id = random_id();
- printf("-> id [ %d ] \n",id);
- if(q!= NULL)
- q=enfileirar(&q,id);
- q=enfileirar(&q,id);
- q=enfileirar(&q,id);
- if (q)
- show(&q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement