Anonymous user
Visualize a tree: Difference between revisions
m
→{{header|Elena}}
m (→Functional composition: Adjusted type comments (Node contents don't have to be strings)) |
|||
Line 534:
`-- (null)</pre>
=={{header|Elena}}==
ELENA
<lang elena>/// a program to produce a visual representation of some tree.
<lang elena>import system'routines.▼
import extensions.▼
class Node
{
constructor
theValue := value
theChildren :=
constructor
<=
constructor new(Node[] children
<=
▲ get = theValue.
}
extension treeOp
{
writeTree(node, prefix)
var children := node
var length := children
children
self
self
var nodeLine := prefix + (index==length).iif(" ","| ")
self
^ self
writeTree(node)
= self
}
public program()
{
var tree := Node
Node
Node
Node
}),
Node
})
console
{{out}}
<pre>
|