// Tree definition for problem 3
type BST =
| Empty
| TreeNode of int * BST * BST
let rec insert value tree =
match tree with
// if tree is empty, add node with no following nodes
| Empty -> TreeNode(value, Empty, Empty)
// if tree has existsing node and new node value is less than previous node
// then insert it on the left side of the existing node
| TreeNode(oldVal, node1, node2) when value < oldVal -> TreeNode(oldVal, insert value node1, node2)
// will recursively go until right spot is found
// if tree has existing node and new node value is greater than previous node
// then insert it on the right side of the existing node
| TreeNode(oldVal, node1, node2) when value > oldVal -> TreeNode(oldVal, node1, insert value node2)
// will recursively go until right spot is found
// when value = oldVal, no insertion will take place since it already exists in the tree
| _ -> tree
let rec contains value = function
| Empty -> false
| TreeNode(compareVal, node1, node2) ->
if value = compareVal then true
elif value < compareVal then contains value node1
else contains value node2
let rec count func = function
| Empty -> 0
| TreeNode(value, node1, node2) ->
(count func node1) + (count func node2) + (if (func value) then 1 else 0)
let evenCount tree =
let result = count (fun value -> value % 2 = 0) tree
result
//printfn "%A" result
let bt1 = insert 10 Empty
let bt2 = insert 5 bt1
let bt3 = insert 3 bt2
let bt4 = insert 17 bt3
let bt5 = insert 12 bt4
let answer = evenCount bt5