examples: use Empty instead of Leaf in tree_of_nodes.v
parent
944bb294e3
commit
0da40c4ea9
|
@ -1,6 +1,6 @@
|
||||||
type Tree = Leaf | Node
|
type Tree = Empty | Node
|
||||||
|
|
||||||
struct Leaf {}
|
struct Empty {}
|
||||||
|
|
||||||
struct Node {
|
struct Node {
|
||||||
value int
|
value int
|
||||||
|
@ -13,14 +13,14 @@ struct Node {
|
||||||
// => it needs an explicit int(0) cast here:
|
// => it needs an explicit int(0) cast here:
|
||||||
fn size(tree Tree) int {
|
fn size(tree Tree) int {
|
||||||
return match tree {
|
return match tree {
|
||||||
Leaf { int(0) }
|
Empty { int(0) }
|
||||||
Node { 1 + size(tree.left) + size(tree.right) }
|
Node { 1 + size(tree.left) + size(tree.right) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
node1 := Node{30, Leaf{}, Leaf{}}
|
node1 := Node{30, Empty{}, Empty{}}
|
||||||
node2 := Node{20, Leaf{}, Leaf{}}
|
node2 := Node{20, Empty{}, Empty{}}
|
||||||
tree := Node{10, node1, node2}
|
tree := Node{10, node1, node2}
|
||||||
println('tree structure:\n $tree')
|
println('tree structure:\n $tree')
|
||||||
println('tree size: ${size(tree)}')
|
println('tree size: ${size(tree)}')
|
||||||
|
|
Loading…
Reference in New Issue