2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
62
Task/Visualize-a-tree/Elena/visualize-a-tree.elena
Normal file
62
Task/Visualize-a-tree/Elena/visualize-a-tree.elena
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#import system.
|
||||
#import system'routines.
|
||||
#import extensions.
|
||||
|
||||
#class Node
|
||||
{
|
||||
#field theValue.
|
||||
#field theChildren.
|
||||
|
||||
#constructor new : value &children:children
|
||||
[
|
||||
theValue := value.
|
||||
theChildren := children toArray.
|
||||
]
|
||||
|
||||
#constructor new : value
|
||||
<= new:value &children:nil.
|
||||
|
||||
#constructor new &children:children
|
||||
<= new:emptyLiteralValue &children:children.
|
||||
|
||||
#constructor new : value &child:child
|
||||
<= new:value &children:(Array new &object:child).
|
||||
|
||||
#method get = theValue.
|
||||
|
||||
#method children = theChildren.
|
||||
}
|
||||
|
||||
#class(extension)treeOp
|
||||
{
|
||||
#method writeTree:node:prefix &subject:childrenProp
|
||||
[
|
||||
#var children := node::childrenProp get.
|
||||
#var length := children length.
|
||||
children zip:(RangeEnumerator new &from:1 &to:length) &eachPair:(:child:index)
|
||||
[
|
||||
self writeLine:prefix:"|".
|
||||
self writeLine:prefix:"+---":(child get).
|
||||
#var nodeLine := prefix + (index==length)iif:" ":"| ".
|
||||
|
||||
self writeTree:child:nodeLine &subject:childrenProp.
|
||||
].
|
||||
^ self.
|
||||
]
|
||||
|
||||
#method writeTree:node &subject:childrenProp
|
||||
= self writeTree:node:"" &subject:childrenProp.
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var tree := Node new &children:
|
||||
(
|
||||
Node new:"a" &children:
|
||||
(
|
||||
Node new:"c" &child:(Node new:"d"),
|
||||
Node new:"d"
|
||||
),
|
||||
Node new:"b").
|
||||
console writeTree:tree &subject:%children.
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue