【发布时间】:2013-11-26 16:50:59
【问题描述】:
人们谈论trees,是的,我可以理解tree 的概念以及traversing 它conceptually 的方式。有趣的是,在binary search tree 中,搜索时间是O(log N)。
现在,我有一些folders in my system,其文件结构为not going to be modified,除了new files are added often。
我可以想象,如果我构建一个表示文件夹结构的二叉搜索树,我可以很好地使用O(log N) 中的文件名进行搜索。我知道这可以通过内置的 .NET 方法非常有效地完成,但我正在尝试查看使用树的真实用例场景。
MSDN here 告诉 'Trees are common data structures because many real-world problems exhibit tree-like behavior. For example, any sort of hierarchical relationship among people, things, or objects can be modeled as a tree. 但是,问题是我无法将上述要求建模为树?
问题是这样的:
I cannot visualize how to connect the BST concept and my requirement。我看到的每一个二叉树样本,都只是通过向节点添加一些简单的整数并遍历它来解释。
如何为目录遍历构建树? (请-一些代码或伪代码,而不仅仅是理论答案!)
如何存储已经建好的树?
(至于从我的文件夹结构中获取所有文件,我使用我的代码here)
【问题讨论】:
-
SO 不适合这类问题。常见问题解答将帮助您为本网站选择正确的问题。我会尝试 Programmers.SE。
标签: c# .net algorithm data-structures tree