我特灵弄清楚https://www.algorithms-and-technologies.com/dfs/r中所示的递归DFS R代码片段所假设的数据结构。我最初假设它是一个邻接列表,类似于:
start <- list(
"0" = c("1","2"),
"1" = c("3","4"),
"2" = c("5","6"),
"3" = c(),
"4" = c(),
"5" = c(),
"6" = c()
)
但我没办法让它工作有人能帮帮我吗
我特灵弄清楚https://www.algorithms-and-technologies.com/dfs/r中所示的递归DFS R代码片段所假设的数据结构。我最初假设它是一个邻接列表,类似于:
start <- list(
"0" = c("1","2"),
"1" = c("3","4"),
"2" = c("5","6"),
"3" = c(),
"4" = c(),
"5" = c(),
"6" = c()
)
但我没办法让它工作有人能帮帮我吗
1条答案
按热度按时间2lpgd9681#
在我看来,他们似乎是在做这样的假设:
即,每个节点是具有
value
(当被搜索时,其将与target
匹配)和作为相同格式的节点的子节点的列表的列表。编辑以添加:
这段代码将您的
start
转换为thelist
的内容:创建于2023年2月23日,使用reprex v2.0.2
你可以打印
thelist
的最终值,但是它很难看,下面是dput(thelist)
给出的结果的重新格式化版本: