rabashani
rabashani

Reputation: 1483

Data structure for category

I am looking for a data structure to add, remove, get, and find on categories.

For example:

Books

Sports

etc.

I think about using tree from the C5 collection library for example, but it looks like it has only red-black trees. Any suggestions?

Upvotes: 1

Views: 1467

Answers (2)

Brian Gideon
Brian Gideon

Reputation: 48969

A tree would be a good approach, but I get the feeling you are thinking there is going to be a one-size-fits-all data structure that you could use and that is not really how I envision it. I concur with Mark's solution, but recommend a Dictionary instead of a List. That way you can lookup a Category and get its subcategories quickly.

Upvotes: 3

Mark Seemann
Mark Seemann

Reputation: 233477

You can just create a Category class that exposes a list of other Category instances.

public class Category
{
    public Category()
    {
        this.ChildCategories = new List<Category>();
    }

    public string Name { get; set; }

    public IList<Category> ChildCategories { get; private set; }
}

Upvotes: 5

Related Questions