v / examples
Raw file
		
1import datatypes
2
3struct KeyVal {
4mut:
5 key int
6 val int
7}
8
9fn (a KeyVal) == (b KeyVal) bool {
10 return a.key == b.key
11}
12
13fn (a KeyVal) < (b KeyVal) bool {
14 return a.key < b.key
15}
16
17fn main() {
18 mut bst := datatypes.BSTree<KeyVal>{}
19 bst.insert(KeyVal{ key: 1, val: 12 })
20 println(bst.in_order_traversal())
21
22 bst.insert(KeyVal{ key: 2, val: 34 })
23 bst.insert(KeyVal{ key: -2, val: 203 })
24
25 for elem in bst.in_order_traversal() {
26 println(elem.val)
27 }
28}