home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!munnari.oz.au!metro!seagoon.newcastle.edu.au!scorch!harris
- From: harris@scorch.apana.org.au (Michael Brown)
- Subject: Re: Btree, or Linked List Questions
- Organization: Craggenmoore public Unix system , Newcastle , Oz
- Date: Sat, 23 Jan 1993 18:29:57 GMT
- Message-ID: <1993Jan23.182957.25180@scorch.apana.org.au>
- References: <C13soz.73L@murphy.com> <1993Jan21.015358.24137@g2syd.genasys.com.au>
- Lines: 31
-
- senerat@g2syd.genasys.com.au (Senerat Rajakaruna) writes:
-
-
- |The right way to free a linked list is to save the next pointer of head
- |before freeing:
- |
- | LIST *p, *q;
-
- | for (p = head; p != NULL; p = q)
- | {
- | q = p -> next;
-
- | /* free any sub-elements of current head */
- | FreeData(p);
- | (void) free((void*) p);
- | }
-
- | /* reset head */
- | head = (LIST *) NULL;
-
-
- for(;(temp_ptr=head_ptr)!=NULL;free(temp_ptr)) head_ptr=head_ptr->next;
-
- I find that a bit more fun, myself.
- --
- .-------------------------------------------------------------------------.
- | Michael Brown at Craggenmoore Public Access Unix |
- | harris@scorch.apana.org.au |
- | "Your progressive hypocrites , hand out their trash. |
- | But it was mine in the first place , so I'll burn them to ash." |
- `--------------------------------------------- Peter Gabriel -------------'
-