KDOXG

Funcao-Clear_LinkedList

Nov 19th, 2018
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct LinkedListDado{
  5.   int cod;
  6.   char nome[40];
  7. }SDado;
  8.  
  9. struct LinkedListNodo{
  10.   SDado info;
  11.   struct LinkedListLista *pNext;
  12. };
  13.  
  14. typedef struct LinkedListLista{
  15.   struct LinkedListNodo *pFirst;
  16. }SLista;
  17.  
  18. void main()
  19. {
  20.  
  21. }
  22.  
  23. void Clear(struct LinkedListNodo *pFirst);
  24.  
  25. void Reset(SLista *pLista)
  26. {
  27.     while (pLista->pFirst->pNext != NULL)
  28.         Clear(pLista->pFirst);
  29.     free(pLista);
  30.     pLista = (SLista *)malloc(sizeof(SLista));
  31. }
  32.  
  33. void Clear(struct LinkedListNodo *pFirst)
  34. {
  35.     struct LinkedListNodo *pAtual, *pAnterior;
  36.  
  37.     if (pFirst->pNext == NULL)
  38.         return;
  39.    
  40.     pAtual = pFirst;
  41.     for (; pAtual->pNext != NULL;)
  42.     {
  43.         pAnterior =  pAtual;
  44.         pAtual = pAtual->pNext;
  45.     }
  46.     free(pAtual);
  47.     pAnterior->pNext = NULL;
  48.     return;
  49. }
Add Comment
Please, Sign In to add comment