--- 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
