- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有结构:
public struct BaseFile
{
public string FileName;
public string Path; // this is not the full path. it is the fullPath of it's parent directory in other words.
}
我有课
public class MyFileDir // can be a file or directory
{
public string Name;
public string FullPath;
public List<MyFileDir> Children;
public bool IsDirectory;
// many more other properties
}
所以我有一个线程将文件放在 LinkedList<BaseFile> myLinkedList
上我也希望另一个线程也开始转换这些文件 MyFileDir root
(请注意,我使用了 linkedList 而不是 list,因为 linkedList 的地址不会改变,而 List 每次需要增长时都会改变其地址)
我有一个 bool 变量 IsRunning,如果另一个线程仍在将基础文件添加到链表,它会告诉我。所以我有类似的东西:
var curNode = myLinkedList.First;
while (IsRunning)
{
if (curNode.Next == null) // wait until next node is not null
{
Thread.Sleep(100);
continue;
}
curNode = curNode.Next;
AddItemToTree(curNode.Value);
}
如您所见,我在执行 AddItemToTree
方法时遇到了问题我基本上会喜欢用那种方法开始构建树。所以首先我会查看根目录并搜索我应该添加 curNode.Value
的目录.我很难做到这一点。
最佳答案
MyFileDir root = new MyFileDir(); //root Node
&
var curNode = myLinkedList.First;
while (IsRunning)
{
if (curNode.Next == null) // wait until next node is not null
{
Thread.Sleep(100);
continue;
}
curNode = curNode.Next;
curFileDir = new MyFileDir(curNode);// your cast here
List<string> mylist = curFileDir.FullPath.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries).ToList(); // this gives a list of dirs in FullPath to explore
MyFileDir temp = root;
foreach (string filedirName in mylist)
{
temp = AddNode(temp, filedirName );
}
}
第一个循环意味着如果节点存在则返回它,否则创建它并返回它
private MyFileDir AddNode(MyFileDir parent, string filedirName)
{
foreach (MyFileDir subfiledir in parent.Children)
if (subfiledir.Name == header)
return subfiledir;
MyFileDir filedir = new MyFileDir(fileName);
parent.Children.Add(fileName);
return fileName;
}
关于c# - 根据路径将文件节点添加到树中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12503691/
过去两天我遇到了一个奇怪的问题,但我还无法解决它。我正在尝试从 2 个文本文件中获取单词并将这些单词添加到树中。我选择的获取单词的方法引用这里: Splitting a text file into
例如,像这样的树: 5 / \ 3 6 / \ 7 2 print(tree.branchLenSum()) 将是1+1+2+2=6 树类: class BinaryTre
我正在学习 JavaScript。我是文档对象模型 (DOM) 主题的新手。 我对节点在 DOM 树中的布局方式感到困惑? 我使用了这个 HTML 文件。 List Buy groceries
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
var nodeEnter = node.enter().append("g") .attr("class", "node") .attr("transform", function (d) {
我正在使用数据表来表示我的应用程序中的数据。我有一个功能,可以在单击克隆图标时克隆任何行并动态添加它下面的行。 数据表具有搜索功能,可以搜索表中存在的所有行,但是它只考虑初始页面加载时加载到表中的行。
我已经用 Python 编写了一个 Tree 类,但是我在为它创建迭代器时遇到了问题我希望能够做到 phonebook = MyTree() # Build up tree for node in p
我需要为 FreeBSD 检查这个 libunwind 端口, http://people.freebsd.org/~kib/git/libunwind.git/ 我以前和当我尝试使用命令 check
我已经实现了自己的 AVL 树,并将其用作字典。我想知道,计算以某个字符串开头的所有单词的最快方法是什么。 例如: string prefix = "fa"; output: 4 我已经在 O(n)
我目前正在尝试编写一个使用 2-3-4 树的程序,但我遇到了插入函数的问题。这是相关代码.. int main () { tree234 myTree; myTree.insert("
我的同事问了我这个问题,但我无法想出任何最佳解决方案。 给定一棵具有n 个节点、n-1 条边和 q 个查询的无向加权树。 每个查询都有输入 u v k ,输出位于路径 u to v 的奇数且小于 k
如果我有一个 app.html 模板如下: ${message} test 使用 MyComponent.ts : export class MyComponent { my
我继承了一个 git 存储库,其中树中的提交条目为空 sha1,阻止 FishEye 为存储库编制索引。 $ git fsck Checking object directoriies: 100%(2
这是一个例子。我也许可以在点击函数中弄清楚它,但我不确定从点击函数外部从根开始检查所有子项的最佳方法。谢谢 .node circle { fill: #fff; stroke: stee
我正在使用 Python 批量编辑许多当前看起来像这样的 musicXML 文件: ... -5 -9
假设有一个 8 阶 B 树。这意味着它可以有 8 个指针和 7 个元素。假设字母 A 到 G 存储在这棵 B 树中。所以这棵 B 树只是一个包含 7 个元素的节点。 然后你尝试将 J 插入到树中。没有
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我正在尝试做一个简单的二维“物理”模拟,主要涉及圆形物体的碰撞,为了避免编程我自己的空间索引(四叉树/r-tree/等),我希望使用 Boost 的 R -树。 问题是我在 Boost 文档中找不到任
我正在从 python 字典中读取数据并尝试在下面的树中添加更多书籍元素。下面只是一个示例,我需要复制一个元素及其子元素但替换内容,在这种情况下我需要复制 book 元素但替换标题和作者。
假设我有一个变量,它包含一个 nltk 树类的树。是否有类似 parent() 或返回节点父节点的函数? 最佳答案 您需要一种不同的数据结构:一棵树,其节点包含指向其父节点的指针。 NLTK 现在提供
我是一名优秀的程序员,十分优秀!