Re: [NEWBIE][CODE}] Linked List Trouble :(

From: Daniel Koepke (dkoepke@CALIFORNIA.COM)
Date: 04/27/98


Pure Krome wrote:
>
> --------
> /* Blood Structure added */
> struct blood_structure *blood_list = NULL;      /* global linked list of
> rooms with blood in dem! */
> struct blood_structure head_blood_list;         /* the first structure
> in the blood list        */

Considering that blood_list will only point to the first element of the
linked list, I see no point for head_blood_list.

> void increase_room_blood(int room)
> {
>         bool empty = TRUE;
>         struct blood_structure *temp;
>

>         /* Lets find the room. If no struct exsists, then it will create
> it next */
>         while (temp!= NULL) {
>                 if (temp->number != room)
>                         temp= temp->next;
>                 else {
>                         /* We have the room, so add the info and quit
> the while loop */
>                         temp->amount +=1;
>                         empty = FALSE;
>                         temp = temp->next;
>                 }

I'm wondering what the purpose of a linked list is in this case?  It
seems fairly logical just to add an "int blood;" to the room_data
structure...but, if you want to do it this way, you probably want:

  for (temp = blood_list; temp; temp = temp->next)
    if (temp->number == room) {
      temp->amount++;
      break;
    }

  if (!temp) { /* we didn't find the room */
    CREATE(temp, struct blood_structure, 1);
    temp->number = room;
    temp->amount = 1;
  }

But I think you're over complicating a rather simple thing.

-dak


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