Archived

This topic is now archived and is closed to further replies.

Vendayan

Need help with a tough linked list

Recommended Posts

Vendayan    278
I''m having some trouble with a linked list I need to create for my character class. It will be the list that holds things that are effecting the "natural" state of the character. One of these effects could be a wound, fatigue, hunger, a spell cast on the character, etc.. The biggest problem im having is that I need to figure out how to remove items from the list after a given amount in time that will be stored in each of the nodesand counted down. Also some effects will need to be removed before thier normal duration. For instance wounds could be healed and spells could be disspelled. In which case my list would have to sort for specific effects that should be tossed at that time. Furthermore every time an effect is placed into the list it will have to modify the character class in a slight way and when it is released it will have to undo those changes. Does anyone think they might be able to straighten this problem out for me a bit? ~Vendayan

Share this post


Link to post
Share on other sites
antistuff    122
To remove an item from a linked list

item1->item2->item3

lets say you want to remove item 2
you have a pointer to item1

STEP 1-make a temporary pointer point to item2
STEP 2-then point item1->next to item3
STEP 3-free memory for item2 (use temp pointer)

hoped that helped

as far as i know you need to have a pointer to the item before the item you want to remove, unless you have a double linked list.

Share this post


Link to post
Share on other sites
Vendayan    278
I understand how to remove them but im not sure how to test for durations and how to know which ones to remove when a character is cured of wounds or disspelled of magic

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
When they are created, you calculate the time they will expire and put it in the data structure. Just check during so many update phases if the item shoudl be removed. If the order of the list''s items isn''t important, then you can order your list so that the condition to be taken off next is the node pointed to by the list''s headptr. That way you don''t have to traverse the whole list to find which conditions need to be removed.

Share this post


Link to post
Share on other sites