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>
- #define MAX 10
- struct Info {
- int vetor[MAX],x,v[MAX],prateleiras1[MAX];
- char str[MAX];
- };
- typedef struct Info info;
- typedef struct Celula {
- info *dados;
- struct Celula *ant;
- struct Celula *prox;
- }cel;
- int size =0x0;
- 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 Push(cel **c,int pos,info *idAviao)
- {
- cel *novo = (cel *) malloc(sizeof(cel));
- cel *aux;
- int y,r,t_clock,Mm;
- t_clock = rand() %60;
- srand(time(NULL));
- if (novo == NULL)
- {
- fprintf(stderr," erro "); exit( 0 );
- }
- novo->dados = p;
- novo->prox = NULL;
- novo->ant = (*c);
- for(y=t_clock; y >=0; y--){
- sleep( 1 ) /* Para Windows Sleep(1000); */
- 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->prateleiras1[ pos ] = IdAviao;
- sleep( 2 );
- printf("\nAVIAO => %d DECOLADO COM SUCESSO \n",IdAviao);
- 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;
- }
- }
- }
- size++;
- return true;
- }
- void ShowList(cel **c)
- {
- size_t count=0;
- cel *pointer;
- pointer = (*c)->prox;
- if(isEmpty(*c))
- printf("----LISTA VAZIA----");
- if (!isEmpty(*c))
- for(; count <= size; count++)
- printf("%d \n",pointer->dados->vetor[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");
- }
- int main()
- {
- int _opc,elem,pos,tam_v,x;
- info p;
- cel *c = cria_cel();
- for(;;){
- x= random_id();
- printf("\n\t(0)---------- SAIR ");
- printf("\n\t(1)---------- INSERIR ELEMENTO NO INICIO DA LISTA (PUSH) ");
- printf("\n\t(3)---------- IMPRIMIR ");
- printf("\n\t(6)---------- LIBERAR LISTA \n");
- printf("> "); scanf("%d",&_opc);
- switch(_opc){
- case 0:
- exit( 0 );
- // break;
- default:
- fprintf(stdout,"[-] COMANDO INVALIDO!!! [-]");
- break;
- case 1:
- printf("Informe a posicao do vetor:\n ");
- printf("> "); scanf("%d",&pos);
- //p.prateleiras1[pos] = elem;
- Push(&c,pos,x);
- break;
- case 2:
- printf("\n POP \n");
- Pop(&c);
- break;
- case 3:
- ShowList(&c);
- break;
- case 4:
- tam_v = sizeList(&c);
- printf("\n TAMANHO DA LISTA -> [ %d ]\n",tam_v);
- break;
- case 5:
- printf("Digite o item de busca: ");
- scanf("%d",elem);
- SearchList(&c,elem);
- break;
- case 6:
- libera_lista(&c);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement