data-structures - 如何创建像树一样的数据结构
问题描述
对于我的项目,我需要构建一个树形结构。我正在寻找一种在叶子上种植它的方法。我通过使用 listy 结构简化了我失败的尝试:
my $root = a => (b => (c=> Nil));
my $here := $root;
while $here.value ~~ Pair {
$here := $here.value;
}
$here = d => Nil;
这不起作用,因为我当然不能更改 Nil。无法分配给不可变的值我怎样才能使它工作?
谢谢, Theo van den Heuvel
解决方案
我认为您收到“无法分配给不可变值”的错误消息是因为该值不是容器。这是我将叶节点设为容器的示例:
my $root = a => (b => (my $ = (c => Nil)));
my $here := $root;
while $here.value ~~ Pair {
$here := $here.value;
}
$here = d => Nil;
现在,没有错误消息。
推荐阅读
- python - 绘制特定数据集
- c - 我如何使用 cblas dgemv 来乘以不同的维度向量?
- sql - 隐蔽 Oracle 查询到 Sql Server 查询
- sql - 所有数据集的每月平均成本。SQL
- wpf - 首先让 HierachichalDataTemplate 显示子项。(后订单(LRN))
- python - Keras 中的“细胞类”是什么?
- python-3.x - 在不使用 oauth2 的情况下写入公共 google 文件夹和 google 表格?
- docker - 本地牧场主主机在 gui 上不可见
- vba - PowerPoint:循环数组时 VBA 下标超出范围
- c# - 当同名存在多次时无法解析 JSON