Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <time.h>
- #include <unistd.h>
- #define MAX_PISTAS 3
- typedef struct No {
- int fall;
- struct No *prox;
- }elem;
- struct Fila{
- elem *inicio;
- elem *fim;
- };
- typedef struct Node {
- int _size;
- struct Node *_next;
- }decolar;
- struct Queue {
- decolar *begin;
- decolar *end;
- };
- typedef struct Fila fila;
- typedef struct Queue queue;
- int size=0;
- int pista[MAX_PISTAS],prateleiras[MAX_PISTAS];
- int random_id()
- {
- srand(time(NULL) *5);
- return rand() %1000;
- }
- fila *fila_cria(void)
- {
- fila *f= (fila *) malloc(sizeof(fila));
- if (f != NULL)
- f->inicio = NULL;
- f->fim = NULL;
- return f;
- }
- queue *queue_create(void)
- {
- queue *q = (queue *) malloc(sizeof(queue));
- if (q != NULL)
- q->begin = NULL;
- q->end = NULL;
- return q;
- }
- bool isEmpty(fila *f)
- {
- return (f->inicio == NULL);
- }
- bool Empty(queue *q)
- {
- return (q->begin == NULL);
- }
- bool aterrisar(fila *f,int p,int idAviao)
- {
- elem *no = (elem *) malloc(sizeof(elem));
- int y,r,Mm=0,clock;
- no->fall =0;
- no->prox = NULL;
- if (no == NULL)
- {
- fprintf(stderr," erro \n"); exit( 0 );
- }
- srand(time(NULL));
- clock = rand() % 30;
- printf("\n\nOK\n\n");
- for(y=clock; y >=0; y--){
- sleep( 1 );
- printf("Tempo previsto Para Aterrisagem [ %d ] \n",y);
- if (y == 0){
- Mm =Mm+1;
- if (Mm == 1)
- r = rand() % 4;
- if (r == 2 || r== 3 || r==4){
- printf("\naviao aterrisando...\n");
- sleep( 2 );
- //no->prox = NULL;
- prateleiras[ p ] = idAviao;
- printf("\n\nAviao Aterrisado com Sucesso \n\n");
- if (isEmpty(f))
- f->inicio = no;
- else
- f->fim->prox = no;
- }else {
- printf("\n\nAviao Caiu \n\n");
- no->fall++;
- }
- }
- }
- size++;
- f->fim = no;
- return true;
- }
- bool decolar_aviao(queue *q,int p, int IdAviao)
- {
- decolar *node = (decolar *) malloc(sizeof(decolar));
- int y,r,clock,Mm;
- srand(time(NULL));
- if (node == NULL)
- {
- fprintf(stderr, " erro "); exit( 0 );
- }
- node->_next = NULL;
- node->_size =0;
- for(y=clock; y >=0; y--){
- sleep ( 1 );
- printf("Tempo espeerado para a decolagem %d \n",y);
- if (y== 0){
- Mm = Mm+1;
- if (Mm == 1)
- r = rand() % 4;
- if (r == 1 || r==2 || r== 3){
- sleep( 2 );
- printf("Aviao %d Decolando \n",IdAviao);
- prateleiras[ p ] = IdAviao;
- printf("Aviao Decolado Com Sucesso \n");
- if (Empty(q))
- q->begin =node;
- else
- q->end->_next = node;
- }else {
- printf("\n\nAviao sem combustivel \n\n");
- }
- }
- }
- q->end = node;
- node->_size++;
- return true;
- }
- void imprime()
- {
- int i;
- for(i=0; i < size; i++)
- printf("Elemento da Prateleiras => ID Aviao: %d \n",prateleiras[ i ]);
- }
- int main()
- {
- fila *f = fila_cria();
- int x = random_id();
- //srand(time(NULL));
- //aterrisar(f,0,x);
- //imprime(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement