Files
v/examples/tree_of_nodes.v
Alexander Medvednikov cf16fefe55 macos: fix failures in the default-cache CI run (#31031)
* macos: fix CI formatting and older SDK TCC headers

* crdt: format gcounter tests for CI

* crdt: remove trailing blank lines caught by CI

* vfmt: format files reported by macOS CI

* veb.csrf: use context configuration when clearing cookies

* math: provide logf in pure V builds

* math: correctly round pure V square roots

* transform: preserve generic elements in fixed array loops

* cgen: escape bool field names for stdbool compatibility

* json2: release JSON5 decoding scratch and cloned map keys

* examples: use pointer recursion in the binary search tree

* modulecache: preserve static macro definitions in declaration headers

* macos: fix declaration test scanning and recursive tree example

* test-self: isolate compiler environment flags from nested builds

* cgen: preserve interface dispatch and module roots with warm caches

* tests: correct backend fixtures exercised by macOS CI

* transform: decode escaped bool generic arguments

* tests: align GC and closure checks with native declarations

* tests: match current HTML tag formatting in option output

* cgen: retain mutable struct addresses in integer casts

* transform: retain explicit generic method calls when ordering arguments

* checker: retain nested translated array types in pointer comparisons

* tests: retain type storage and canonicalize macOS temporary paths

* graphql: store recursive AST edges through pointers

* veb: avoid copying large request and response structs for connection checks

* veb.csrf: expire cleared cookies at the configured path
2026-10-22 16:38:25 +03:00

28 lines
578 B
V

type Tree = Empty | &Node
struct Empty {}
struct Node {
value int
left Tree
right Tree
}
// Note: a match expression, infers the type of its result
// from the type of the return value in the first branch,
// => it needs an explicit int(0) cast here:
fn size(tree Tree) int {
return match tree {
Empty { int(0) }
&Node { 1 + size(tree.left) + size(tree.right) }
}
}
fn main() {
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)}')
}