home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20121 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.4 KB  |  42 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!munnari.oz.au!metro!seagoon.newcastle.edu.au!scorch!harris
  3. From: harris@scorch.apana.org.au (Michael Brown)
  4. Subject: Re: Btree, or Linked List Questions
  5. Organization: Craggenmoore public Unix system , Newcastle , Oz
  6. Date: Sat, 23 Jan 1993 18:29:57 GMT
  7. Message-ID: <1993Jan23.182957.25180@scorch.apana.org.au>
  8. References: <C13soz.73L@murphy.com> <1993Jan21.015358.24137@g2syd.genasys.com.au>
  9. Lines: 31
  10.  
  11. senerat@g2syd.genasys.com.au (Senerat Rajakaruna) writes:
  12.  
  13.  
  14. |The right way to free a linked list is to save the next pointer of head 
  15. |before freeing:
  16. |    
  17. |    LIST *p, *q;
  18.  
  19. |    for (p = head; p != NULL; p = q)
  20. |    {
  21. |        q = p -> next;
  22.  
  23. |        /* free any sub-elements of current head */
  24. |        FreeData(p);
  25. |        (void) free((void*) p);
  26. |    }
  27.  
  28. |    /* reset head */
  29. |    head = (LIST *) NULL;
  30.  
  31.  
  32.     for(;(temp_ptr=head_ptr)!=NULL;free(temp_ptr)) head_ptr=head_ptr->next;
  33.     
  34.     I find that a bit more fun, myself.
  35. -- 
  36.  .-------------------------------------------------------------------------.
  37.  |             Michael  Brown  at Craggenmoore Public Access Unix          |
  38.  |                         harris@scorch.apana.org.au                      |
  39.  |    "Your progressive hypocrites , hand out their trash.                 |
  40.  |        But it was mine in the first place , so I'll burn them to ash."  |
  41.  `--------------------------------------------- Peter Gabriel -------------'
  42.