How to implement a category hierarchy using collections

Posted by Luke101 on Stack Overflow See other posts from Stack Overflow or by Luke101
Published on 2010-04-14T00:05:13Z Indexed on 2010/04/14 0:53 UTC
Read the original article Hit count: 223

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET