您好,假设您有普通的 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/