类别的数据结构
I am looking for a data structure to add, remove, get, and find on categories.
For example:
Books
- Drama
- Science fiction
- Other
Sports
- Cycling
- Golf
- Team Sports
- Soccer
- Football
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需创建一个公开其他类别实例列表的类别类。
You can just create a Category class that exposes a list of other Category instances.
树是一种很好的方法,但我感觉您认为将有一种可以使用的通用数据结构,但这并不是我的设想。我同意马克的解决方案,但推荐使用字典而不是列表。这样您就可以查找类别并快速获取其子类别。
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.