Advertisement
juan_de99

Untitled

Oct 30th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. typedef struct sNodo{
  2.     void* dato;
  3.     unsigned cantB;
  4.     struct sNodo *sig;
  5. }tNodo;
  6.  
  7. typedef tNodo* tLista;
  8.  
  9.  
  10. void crearLista(tLista *lista);
  11. int listaVacia(const tLista *lista);
  12. int listaLlena(const tLista *lista,unsigned cantB);
  13. int ponerAlFinal(tLista *lista,const void* dato,unsigned cantB);
  14.  
  15.  
  16.  
  17. void crearLista(tLista *lista){
  18.     *lista=NULL;
  19.  
  20. }
  21.  
  22. int listaVacia(const tLista *lista){
  23.     return *lista==NULL;
  24. }
  25.  
  26. int listaLlena(const tLista *lista,unsigned cantB)
  27. {
  28.     tNodo *aux;
  29.  
  30.     aux=(tNodo*)malloc(sizeof(tNodo));
  31.     if(!aux)
  32.         return 0;
  33.     aux->dato=malloc(cantB);
  34.  
  35.     free(aux->dato);
  36.     free(aux);
  37.  
  38.     return !aux->dato;
  39. }
  40.  
  41. int ponerAlFinal(tLista *lista,const void* dato,unsigned cantB)
  42. {
  43.     tNodo *nodo;
  44.    
  45.     nodo=(tNodo*)malloc(sizeof(tNodo));
  46.    
  47.     if(!nodo)
  48.         return 0;
  49.    
  50.     nodo->dato=malloc(cantB);
  51.    
  52.     if(!nodo->dato){
  53.         free(nodo);
  54.         return 0;
  55.     }
  56.    
  57.     memcpy(nodo->dato,dato,cantB);
  58.     nodo->cantB=cantB;
  59.     nodo->sig=NULL;
  60.    
  61.     while(*lista)
  62.         lista=&(*lista)->sig;
  63.    
  64.     (*lista)=nodo;
  65.    
  66.     return 1;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement