c++ - 路径树到树结构

标签 c++ algorithm tree

您好,假设您有普通的 UNIX 路径树作为输入(作为字符串)。

root 0
root/file1.txt 1
root/file2.txt 2
root/folder1 3
root/folder1/file3.txt 4
root/folder1/file4.txt 5
e.t.c.

将此字符串转换为树数据结构的更好方法是什么?

最佳答案

像这样:

为“\”创建根节点

node=root;
token=getNextToken(inputString);
while (token){
 if (!node.childExist(token)) node.createChild(token)
 node=node.Child(token)
 token=getNextToken(inputString);
}

关于c++ - 路径树到树结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11909995/

相关文章:

c++ - 判断虚函数是否重载

c++ - 将 cuda 文件添加到 visual studio 中的现有 c 项目

string - 如果我知道所有句子的发音,如何获得句子中汉字的发音?

c++ - 什么是 xtree 是 Visual C++?

android - 如何从 Android Studio 调用 C++ 源代码?

c++ - 读取传感器数据的线程或定时器?

c - 有序二叉树插入

c++ - 寻找 C4.5 算法的 C++ 实现

python - 用python遍历树的解决方案

algorithm - 用于在树中查找支配集的多项式时间算法