[Code] Problems with Linked List

From: - Pure Krome - (pure@SPRINT.COM.AU)
Date: 10/25/97


G'day all.
    i've spent a fair amount of time yesterday doing this and i can't
finish the last bit.
(*getting frustrated*).

I have created a linked list, that when ever a player does this thing,
it checks to see if it's in the linked list. If not, it adds it to the
end of the list. So far so good. It saves and reloads back into the game
also..

Now the problem. I can't seem to removed a structure FROM the linked
list! My alg sucks big time, so i'm wondering if someone could lead me
in the right direction.
Also, are there macros for removing and adding into linked lists in the
code?

- Start of code -
/* NOTE : If the stuct starts out having hours && vnum = -1, then the
struct is _empty_. This
   is initilised to -1, -1, NULL, when the char is created. */

    end = FALSE;
   /* Get the current  structure */
   head = ch->char_rent_info;
   /* Make the temp structure point to the address (contents) of the
first struct. */
   temp = &head;
   previous = NULL; /* Previous isn't pointing to anything yet. */

   /* run through the structs until the end */
   if ((temp->vnum == -1) && (temp->hours == -1))
    return;

   while (end == FALSE)
   {
    /* In here means there is a structure(s), so check em out */
    if (temp->hours == 0)
     /* Remove this struct */
    {
     /* are there more structs ? */
     if (temp->next != NULL)
      /* yes there are */
     {
      if (previous != NULL) /* there are some previous structs. */
       previous->next = temp->next; /* the previous link, links to the
next struct. */
      temp = temp->next; /* the current == the next structure */

     }
     else
      /* At the end of the struct */
     {
      temp = NULL;
      /* Check to see if we are at the start of the list */
      if (previous != NULL)
      {
       temp = previous;
       previous->next = NULL; /* Remember, there is more structs. */
      }
      else
      /* Here means there is only ONE struct, and this is it, so reset
it */
      {
       head.vnum = -1;
       head.hours = -1;
       head.next = NULL;
      }
      end = TRUE;
     }
     /* Now destroy this struct */
    }
    else
     /* Decrement this struct, and continue onwards! */
    {
     temp->hours--;
     previous = temp;
     if (temp->next != NULL)
      temp = temp->next;
     else
      end = TRUE;
    }
   }

  ch->char_rent_info = head;
  }


Thanks. ;)

Oh. If there are some examples in the code where linked lists are
removed / added, could someone also suggest where?
I'm just about to try and look for some, starting with spell affects ...
*shrug*

Jussy


     +------------------------------------------------------------+
     | 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/08/00 PST