How to implement a category hierarchy using collections
- by Luke101
Hello,
I have about 200 categories that are nested. I am currently reading the documention on the C5 generics library. I am not sure if the C5 library is overkill or not. I am looking at converting all my custom algorithms to the C5 implemention.
This is what I need. If a certain category is chosen i need to find its parents, siblings, direct children, and all children.
This is the way I have it set up. To find the:
Parents:
I start from the current location then loop through the list and find the current parent. When I find the parent I loop through the whole list again to find the next parent and so on.
Siblings:
I loop through the whole list and find all the nodes that have the same parent as the choosen node.
direct children:
I loop through the whole list and find all nodes that is a parent of the choosen node.
All Children:
This one took me a while to figure out. But I used recursion to find all children of the choosen node.
Is there a better way to implement something like this?