[NEWBIE] Chopping off linked lists

From: Mark Gerritsen (m.p.h.gerritsen@STUDENT.UTWENTE.NL)
Date: 04/20/98


I've got a question about linked lists:
I've got a list where if an entry has a certain field set to 0, every next
entry in the list will have that field set to 0 too. As soon as that value
is 0, I want to remove the entry from the list (so just the last few
entries) Can I just do a:
j->next = NULL;
or do you have to loop through the list and do a REMOVE_FROM_LIST for every
entry with the field set to 0? If so, would it work like this?

  for (j = list; j; j = j->next) {
    if (j->field == 0)
      REMOVE_FROM_LIST(j, list, next);

I'm not quite sure what will happen to j->next->next, j->next->next->next,
etc if I just do "j->next = NULL;"... would it be a bad thing to do it like
that? Is there an easier way?

Havoc of Dagmarck (Mark Gerritsen)

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |

This archive was generated by hypermail 2b30 : 12/15/00 PST