Advertisement
luciana1237

Untitled

Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. typedef struct No {
  6.     int x;
  7.     struct No *inicio;
  8.     struct No *fim;
  9.     struct No *prox;
  10. }fila;
  11.  
  12. fila *fila_cria(void)
  13. {
  14.     fila *f = (fila *) malloc(sizeof(fila));
  15.    
  16.     if (f != NULL)
  17.         f->inicio = NULL;
  18.         f->fim = NULL;
  19.     return f;
  20. }
  21.  
  22. bool isEmpty(fila *f)
  23. {
  24.     return (f->inicio== NULL);
  25. }
  26.  
  27. bool enfileirar(fila *f,int v)
  28. {
  29.     fila *no = (fila *) malloc(sizeof(fila));
  30.     fila *p,*aux;
  31.     if (no == NULL)
  32.         fprintf(stderr,"erro");
  33.        
  34.     no->x=v;
  35.     no->prox = NULL;
  36.    
  37.     if (isEmpty(f)){
  38.         printf("fila vazia");
  39.         p->inicio = no;
  40.        
  41.     }else{
  42.         printf("nai");
  43.         aux = p->prox;
  44.         while(aux->prox != NULL){
  45.             aux = aux->prox;
  46.             p->fim->prox = no;
  47.    
  48.         }    
  49.     }
  50.     p->fim = no;
  51.     return true;
  52. }
  53.  
  54. int main()
  55. {
  56.     fila *f= fila_cria();
  57.     enfileirar(f,3);
  58.     enfileirar(f,3);
  59.     enfileirar(f,3);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement