I have a task and I can’t understand how to make one question. Here is what I need to do:
Write a function that collects all the elements in the tree T, which satisfies the property p and returns it. Turn the tree in order. Find all elements in BST that satisfy f using continued success.
I have done the following:
datatype 'a tree =
Empty | Node of (int * 'a) * 'a tree * 'a tree
fun find_all f Empty cont = cont()
| find_all f (Node(x, l, r)) cont = if (f x) then find_all (f l (fn x => x::cont())) @ find_all (f r (fn x => x::cont()))
else find_all (f l (fn () => cont())) @ find_all (f r (fn () => cont()));
I do not understand why it does not work ...
source
share