1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/bst_map.v

29 lines
452 B
V

import datatypes
struct KeyVal {
mut:
key int
val int
}
fn (a KeyVal) == (b KeyVal) bool {
return a.key == b.key
}
fn (a KeyVal) < (b KeyVal) bool {
return a.key < b.key
}
fn main() {
mut bst := datatypes.BSTree[KeyVal]{}
bst.insert(KeyVal{ key: 1, val: 12 })
println(bst.in_order_traversal())
bst.insert(KeyVal{ key: 2, val: 34 })
bst.insert(KeyVal{ key: -2, val: 203 })
for elem in bst.in_order_traversal() {
println(elem.val)
}
}