数据结构 – 如何创建像树一样的数据结构

前端之家收集整理的这篇文章主要介绍了数据结构 – 如何创建像树一样的数据结构前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对于我的项目,我需要构建一个树结构.我正在寻找一种在树叶上种植它的方法.我通过使用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

解决方法

我认为你得到的错误信息“无法分配给不可变值”是因为该值不是 container.这是一个我将叶节点作为容器的示例:

my $root = a => (b => (my $= (c => Nil)));
my $here := $root;
while $here.value ~~ Pair {
  $here := $here.value;
}
$here = d => Nil;

现在,没有错误消息.

猜你在找的Perl相关文章