在C#树数据结构 [英] Tree data structure in C#

查看:166
本文介绍了在C#树数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找在C#中的树或图形数据结构,但我想没有一个规定。 使用C#2.0 解释了一下为什么数据结构全面检查。有哪些常用来提供此功能方便的图书馆吗?或许通过一个策略模式来解决这些问题元文章中psented p $。

I was looking for a tree or graph data structure in C# but I guess there isn't one provided. An Extensive Examination of Data Structures Using C# 2.0 explains a bit about why. Is there a convenient library which is commonly used to provide this functionality? Perhaps through a strategy pattern to solve the issues presented in the article.

我觉得自己有点傻实现我自己的树,就像我会实现我自己的ArrayList。

I feel a bit silly implementing my own tree, just as I would implementing my own ArrayList.

我只想要一个普通的树,可能不平衡。想想一个目录树。 C5看起来漂亮,但他们的树形结构看起来就像平衡红黑树更适合不是重新presenting节点的层次结构进行搜索得以实施。

I just want a generic tree which can be unbalanced. Think of a directory tree. C5 looks nifty, but their tree structures seem to be implemented as balanced red-black trees better suited to search than representing a hierarchy of nodes.

推荐答案

我最好的建议将是没有标准树数据结构,因为有你可以实现它这么多的方法,这将是不可能覆盖所有基地一个解决方案。更具体的解决方案中,不太可能是适用于任何给定的问题。我甚至得到恼火LinkedList的 - 如果我想一个循环链表

My best advice would be that there is no standard tree data structure because there are so many ways you could implement it that it would be impossible to cover all bases with one solution. The more specific a solution, the less likely it is applicable to any given problem. I even get annoyed with LinkedList - what if I want a circular linked list?

您需要实现将是节点的集合,这里的基本结构有一些选项,让您开始。让我们假设该类节点是基类中的整个解决方案。

The basic structure you'll need to implement will be a collection of nodes, and here are some options to get you started. Let's assume that the class Node is the base class of the entire solution.

如果您只需要向下导航树,然后节点类需要儿童的名单。

If you need to only navigate down the tree, then a Node class needs a List of children.

如果您需要导航到上树,则节点类需要一个链接到它的父节点。

If you need to navigate up the tree, then the Node class needs a link to its parent node.

建立一个的AddChild方法,它有这两点和其他任何商业逻辑必须实现的所有细节的照顾(孩子的限制,整理孩子,等等。)

Build an AddChild method that takes care of all the minutia of these two points and any other business logic that must be implemented (child limits, sorting the children, etc.)

这篇关于在C#树数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆