examples: use Empty instead of Leaf in tree_of_nodes.v

pull/8125/head^2
Delyan Angelov 2021-01-15 11:15:29 +02:00
parent 944bb294e3
commit 0da40c4ea9
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 5 additions and 5 deletions

View File

@ -1,6 +1,6 @@
type Tree = Leaf | Node
type Tree = Empty | Node
struct Leaf {}
struct Empty {}
struct Node {
value int
@ -13,14 +13,14 @@ struct Node {
// => it needs an explicit int(0) cast here:
fn size(tree Tree) int {
return match tree {
Leaf { int(0) }
Empty { int(0) }
Node { 1 + size(tree.left) + size(tree.right) }
}
}
fn main() {
node1 := Node{30, Leaf{}, Leaf{}}
node2 := Node{20, Leaf{}, Leaf{}}
node1 := Node{30, Empty{}, Empty{}}
node2 := Node{20, Empty{}, Empty{}}
tree := Node{10, node1, node2}
println('tree structure:\n $tree')
println('tree size: ${size(tree)}')