[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
linked lists
Hi,
How do you make list modification and referral work cleanly together?
Suppose I want to have two lists A and B. Would you normally refer to
them with a pointer as below?
struct list_container {
struct list_element *a;
struct list_element *b;
} container;
struct list_element {
int var;
...
struct list_head list;
};
If I refer to a list by referring to an element from it with a
pointer, removal becomes complex because then every time I remove an
element I have to explicitly check whether that particular element is
the reference used in the container and also modify that if so. Do you
have a better solution to this? Furthermore it makes it complex to
handle the last element. Imagine list A is depleted, then I set
container.a to null to indicate nothing is there. Then everytime I
refer to that list I have to check whether its null first.
How do you make list modification and reference work together? Any better ways?
Thanks,
Bahadir
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/