Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FILAS em C Segue o padrC#o LIFO */
- /*Last In First Out = Ultimo a entrar e o ultimo a sair */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <time.h>
- #include <unistd.h>
- #define MAX_PRATELEIRAS 10
- #define MAX_PISTAS 10
- int size=0;
- struct t_clock
- {
- int Mm,Hh,Hours,Minutes,Secunds;
- };
- typedef struct t_celula
- {
- int prateleiras[MAX_PRATELEIRAS],pistas[MAX_PISTAS],values;
- struct t_celula *prox;
- struct t_celula *begin;
- struct t_celula *end;
- }queue;
- typedef struct t_clock t_time;
- int random_id()
- {
- srand(time(NULL));
- return rand() %1000;
- }
- bool isEmpty(queue **q)
- {
- return((*q)->end == NULL);
- }
- queue *queue_create()
- {
- queue * q = (queue *) malloc(sizeof(queue)); /* Alocando memoria dinamicamente */
- if (q != NULL)
- q->prox = NULL;
- q->begin= NULL;
- q->end = NULL;
- return q;
- };
- queue *enfileirar(queue **q,int IdAviao)
- {
- queue *novo_elemento = (queue *) malloc(sizeof(queue));
- t_time *clock_t = (t_time *) malloc(sizeof(t_time));
- clock_t->Hh =0;
- int r,y;
- if (novo_elemento == NULL)
- {
- fprintf(stderr,"erro \n");
- exit( 0 );
- }
- if (novo_elemento != NULL)
- novo_elemento->values = IdAviao;
- novo_elemento->prox = NULL;
- srand(time(NULL));
- r = rand() %4;
- if (r == 1 || r==2 || r==3 || r==4){
- clock_t->Mm = rand() %10;
- for(y=clock_t->Mm; y >=0; y--){
- sleep( 1 );
- printf("\nTEMPO PREVISTO PARA DECOLAGEM %d \n",y);
- if(y == 0)
- if((*q)->end == NULL){
- printf("\n---VAZIA---\n");
- (*q)->begin = novo_elemento;
- }else{
- printf("\nTEM\n");
- (*q)->end->prox = novo_elemento;
- }
- }
- }else
- {
- printf("AVIAO CAIU\n");
- }
- size++;
- (*q)->end = novo_elemento;
- return novo_elemento;
- }
- void imprime(queue **q)
- {
- queue *pointer;
- //pointer =(*q);
- int i;
- for(i=0; i <size; i++)
- printf("[ %d ]\n",(*q)->values);
- }
- int main()
- {
- int ID,opc;
- ID = random_id();
- printf("ID -> %d \n",ID);
- for(;;){
- printf("\n\t(0)_____________[ SAIR ] ");
- printf("\n\t(1)_____________[ ENFILEIRAR ]");
- printf("\n\t(2)_____________[ IMPRIMIR ]\n");
- printf("> "); scanf("%d",&opc);
- switch(opc){
- case 0:
- exit( 0 );
- default:
- break;
- case 1:
- enfileirar(&q,)
- }
- }
- queue *q = queue_create();
- q=enfileirar(&q,ID);
- q=enfileirar(&q,ID);
- imprime(&q);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement