--- ~Rick <[EMAIL PROTECTED]> wrote:
> I am creating some singly-linked lists. I am having
> some trouble
> deleting nodes. There are two areas where I am
> having difficulty.
>
> The first is deleting the first node. I pass the
> base address of the
> list to the function, and want to change the value
> upon return.
> Setting "llist = first;" does not seem to work.
> Setting "*llist =
> first;" generates a compiler error. Below is my
> code.
>
> void delete_first_node(struct ENTRY *llist)
> {
> struct ENTRY *temp;
> struct ENTRY *first;
>
> temp = llist;
> first = llist -> next;
> delete temp;
>
> llist = first;
>
> return;
> }
>
> The second area of difficulty is related. After I
> delete the list,
> because I can't set the head node to NULL, I can
> still access list
> elements. I "delete" (free) them, but they are still
> "active". I
> assume once I get the head node properly set to
> NULL, this problem
> will go away.
>
> Thanks!
>
> ~Rick
>
>
You might consider altering your function to return
the value of the NEW first node.
ENTRY* delete_first_node(struct ENTRY *llist)
{
struct ENTRY *temp;
struct ENTRY *first;
temp = llist;
first = llist -> next;
delete temp;
return(first);
}
then change the function call to use the return value.
list = delete_first_node(list);
Mickey M.
Construction Partner Inc.
http://www.constructionpartner.com