我正在尝试创建一个树,其中一个根和26个叶节点是字母表中的字符。是否有任何特定的读数/资源可以帮助我更多地了解Scala中的树结构?
答案 0 :(得分:2)
答案 1 :(得分:2)
这样的东西?
scala> abstract class Tree[A]
defined class Tree
scala> case class Node[A](children : List[Tree[A]]) extends Tree[A]
defined class Node
scala> case class Leaf[A](value : A) extends Tree[A]
defined class Leaf
scala> val root = Node(children = ('A' to 'Z') map (Leaf(_)) toList )
root: Node[Char] = Node(List(Leaf(A), Leaf(B), Leaf(C), Leaf(D), Leaf(E), Leaf(F), ...