At Sunday 6/1/2008 06:17 PM, you wrote:
>--- In [email protected], ~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;
> > }
><snip>
>
>Hi Rick,
>
>this is a typical problem. I've stumbled upon it quite a few times,
>you're not alone. ;-)
>The solution is simple: pass a "struct ENTRY **" to your functions,
>not a "struct ENTRY *"; this way you have the _address_ of the pointer
>to the first node, so you can remove the node and set this address
>correctly.
>
>BTW do you want to write C or C++ code? If it's C code (I seem to
>recall that in C++ you wouldn't always need the "struct", hence the
>question), you should not use "delete"; maybe your compiler accepts it
>in C code, but it should not.
>
>Regards,
>Nico

Thanks Nico.

How would I call the function? Currently I have this:

struct ENTRY    *list;
.
.
delete_first_node(list);

Would I use: delete_first_node(&list);?
Or would I use: delete_first_node(*list);?

RE C vs/ C++. I'm using wxdevC++. I specified the project as being 
C++ and named the source files *.cpp. So, I guess it's C++.

I'm an old C programmer, trying to learn/convert to C++. I initially 
was using malloc/free but decided I should be using new/delete 
instead. I'm probably doing the whole C++ thing all wrong. Maybe I 
should start from scratch.

~Rick

>------------------------------------
>
>To unsubscribe, send a blank message to 
><mailto:[EMAIL PROTECTED]>.Yahoo! Groups Links
>
>
>

Reply via email to