我有一项任务要做,但我不知道如何做一个问题。这是我必须做的:
编写一个函数,收集树 T 中满足属性 p 的所有元素并返回它。依次遍历树。使用成功延续找到 BST 中满足 f 的所有元素。
我做了以下事情:
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()));
我不明白为什么它不起作用...