Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <string.h>
- #include <unistd.h>
- #include <time.h>
- #define MAX 10
- #define MAX_PRATELEIRAS 20
- struct Info {
- int vetor[MAX],x,v[MAX],pista[MAX];
- char str[MAX];
- };
- typedef struct Info info;
- typedef struct Celula {
- info *dados;
- struct Celula *ant;
- struct Celula *prox;
- }cel;
- struct Node {
- unsigned int prateleiras1[MAX_PRATELEIRAS];
- };
- typedef struct Node decolar;
- typedef struct Queue {
- decolar *date1;
- struct Queue *begin;
- struct Queue *_next;
- }queue;
- int size =0x0,fall,_size =0,fuel;
- int random_id()
- {
- srand(time(NULL));
- return rand() %1000;
- }
- cel *cria_cel(void)
- {
- cel *c = (cel *) malloc(sizeof(cel));
- if (c!= NULL)
- c->ant = NULL;
- c->prox = NULL;
- return c;
- }
- bool isEmpty(cel *c)
- {
- return (c->prox == NULL);
- }
- bool Empty(queue *q)
- {
- return (q->_next == NULL);
- }
- bool Push(cel **c,info * pointer,int idAviao)
- {
- cel *novo = (cel *) malloc(sizeof(cel));
- cel *aux;
- int y,r,t_clock,Mm;
- srand(time(NULL));
- t_clock = rand() %6;
- if (novo == NULL)
- {
- fprintf(stderr," erro "); exit( 0 );
- }
- novo->dados = pointer;
- novo->prox = NULL;
- novo->ant = (*c);
- for(y=t_clock; y >=0; y--){
- sleep( 1 ); /* Para Windows Sleep(1000); */
- #ifdef linux /* se o sitema operacional for o linux */
- system("clear");
- #else /* se nao */
- system("cls");
- #endif
- printf("\n\t-=========================================-\n");
- printf("\n\t|TEMPO PREVISTO PARA PROXIMA ATERRISAGEM |\n\n");
- printf("\n\t| TEMPO: \t{ 00 : %d } |\n",y);
- printf("\n\t-=========================================- \n");
- if (y==0){
- Mm=Mm+1;
- if (Mm == 1)
- r = rand() %6;
- if (r == 1 || r==2 || r== 3 || r==4 || r==5){
- sleep( 2 ); /* Para Windows Sleep(2000); */
- printf("\n\t********************************\n");
- printf("\n\t|[+] AVIAO => %d Aterrisando [+]|\n",idAviao);
- printf("\n\t********************************");
- //novo->dados->prateleiras1[ pos ] = idAviao;
- sleep( 2 );
- printf("\nAVIAO => %d ATERRISADO COM SUCESSO \n",idAviao);
- printf("\nOK\n");
- if(isEmpty(*c)){
- (*c)->prox =novo;
- }else{
- printf("tem");
- aux = (*c)->prox;
- while(aux->prox != NULL){
- aux = aux->prox;
- }
- aux->prox = novo;
- aux->ant = aux;
- }
- }else {
- sleep( 3 );
- printf("\n\n[-] AVIAO %d CAIU!! [-]",idAviao);
- fall++;
- size--;
- }
- }
- }
- size++;
- return true;
- }
- void ShowList_aterrisagem(cel **c)
- {
- int count=0;
- cel *pointer;
- pointer = (*c)->prox;
- if(isEmpty(*c))
- printf("----LISTA VAZIA----");
- if (!isEmpty(*c))
- for(; count < size; count++)
- printf("\nPISTA %d AVIAO ID: => [ %d ]\n",count,pointer->dados->pista[count]);
- }
- int sizeList(cel **c)
- {
- size_t count = 0;
- if (!isEmpty(*c)){
- cel *pointer = (*c)->prox;
- for(; pointer != NULL; pointer =pointer->prox)
- count++;
- }if (isEmpty(*c))
- printf("----LISTA VAZIA----");
- return count;
- }
- void libera_lista(cel **c)
- {
- cel *no;
- if (!isEmpty(*c)){
- while((*c)->prox != NULL){
- no = (*c);
- (*c) = (*c)->prox;
- free(no);
- size--;
- }
- }if(isEmpty(*c))
- printf("\n ----LISTA VAZIA----\n");
- }
- queue *queue_create(void)
- {
- queue *q = (queue *) malloc(sizeof(queue));
- if (q != NULL)
- q->begin = NULL;
- q->_next = NULL;
- return q;
- }
- bool enfileirar_decolagem(queue **q,decolar *p,int IDaviao)
- {
- queue *novo = (queue *) malloc(sizeof(queue));
- queue *aux;
- int y,r,t_clock,Mm;
- if(novo == NULL)
- {
- fprintf(stderr," erro ");
- exit( 0 );
- }
- srand(time(NULL));
- t_clock = rand() %6;
- novo->date1 = p;
- novo->_next = NULL;
- novo->begin = (*q);
- for(y=t_clock; y >=0; y--){
- sleep( 1 ); /* Para Windows Sleep(1000); */
- #ifdef linux /* se o sitema operacional for o linux */
- system("clear");
- #else /* se nao */
- system("cls");
- #endif
- printf("\n\t-=========================================-\n");
- printf("\n\t|TEMPO PREVISTO PARA PROXIMA DECOLAGEM |\n\n");
- printf("\n\t| TEMPO: \t{ 00 : %d } |\n",y);
- printf("\n\t-=========================================- \n");
- if (y==0){
- Mm=Mm+1;
- if (Mm == 1)
- r = rand() %6;
- if (r == 1 || r==2 || r== 3 || r==4 || r==5){
- sleep( 2 ); /* Para Windows Sleep(2000); */
- printf("\n\t********************************\n");
- printf("\n\t|[+] AVIAO => %d DECOLANDO [+]|\n",IDaviao);
- printf("\n\t********************************");
- //novo->dados->prateleiras1[ pos ] = idAviao;
- sleep( 2 );
- printf("\nAVIAO => %d DECOLADO COM SUCESSO \n",IDaviao);
- printf("\nOK\n");
- if(Empty(*q)){
- (*q)->_next =novo;
- }else{
- printf("tem");
- aux = (*q)->_next;
- while(aux->_next != NULL){
- aux = aux->_next;
- }
- aux->_next = novo;
- aux->begin = aux;
- }
- }else {
- sleep( 3 );
- printf("\n\n[-] AVIAO %d SEM COMBUSTIVEL!! [-]",IDaviao);
- fuel++;
- _size--;
- }
- }
- }
- _size++;
- return true;
- }
- void ShowList_decolagem(queue **q)
- {
- int count=0;
- queue *pointer;
- pointer = (*q)->_next;
- if(Empty(*q))
- printf("----LISTA VAZIA----");
- if (!Empty(*q))
- for(; count < _size; count++)
- printf("\nPISTA %d AVIAO ID: => [ %d ]\n",count,pointer->date1->prateleiras1[count]);
- }
- void libera_lista_decolagem(queue **q)
- {
- queue *no;
- if (!Empty(*q)){
- while((*q)->_next != NULL){
- no = (*q);
- (*q) = (*q)->_next;
- free(no);
- _size--;
- }
- }if(Empty(*q))
- printf("\n ----LISTA VAZIA----\n");
- }
- int sizeList_decolagem(queue **q)
- {
- int count = 0;
- if (!Empty(*q)){
- queue *pointer = (*q)->_next;
- for(; pointer != NULL; pointer =pointer->_next)
- count++;
- }if (Empty(*q))
- printf("----LISTA VAZIA----");
- return count;
- }
- int main()
- {
- int _opc,elem,pos,tam_v,x,prat;
- info p;
- decolar dc;
- cel *c = cria_cel();
- queue *q = queue_create();
- for(;;){
- x= random_id();
- printf("\n\t(0)----------- SAIR ");
- printf("\n\t(1)----------- INSERIR AVIAO NA FILA DE POUSO ");
- printf("\n\t(2)----------- INSERIR AVIAO NA FILA DE DECOLAGEM ");
- printf("\n\t(3)----------- MOSTRAR FILA ( POUSO ) ");
- printf("\n\t(4)----------- MOSTRAR FILA ( DECOLAGEM )\n");
- printf("> "); scanf("%d",&_opc);
- switch(_opc){
- case 0:
- exit( 0 );
- default:
- fprintf(stdout,"[-] COMANDO INVALIDO!!! [-]");
- break;
- case 1:
- printf("\n INFORME O NUMERO DA PISTA (0 a 3):\n");
- printf("> "); scanf("%d",&pos);
- p.pista[pos] = x;
- Push(&c,&p,x);
- break;
- case 2:
- printf("\n INFORME O NUMERO DA PRATELEIRA (0 a 4): ");
- scanf("%d",&prat);
- dc.prateleiras1[prat] =x;
- enfileirar_decolagem(&q,&dc,x);
- break;
- case 3:
- ShowList(&c);
- break;
- case 4:
- ShowList_decolagem(&q);
- break;
- case 6:
- libera_lista(&c);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement