需要的是編寫''a tree -> (''a * ''a -> bool) -> ''a -> bool
類型的函數searchBST,該函數searchBST搜索給定數據元素的nst。使用:如何在標準ML中編寫BST搜索功能?
datatype 'data tree = Empty
| Node of 'data tree * 'data * 'data tree
此外,我們還不能搜索樹中的每一個節點,但只有那些,根據定義,可能包含我們正在尋找的元素節點。
我寫的功能是(int * int tree -> bool)
型的,我將不勝感激它轉換爲所需類型
datatype 'data tree = Empty
| Node of 'data tree * 'data * 'data tree;
fun searchBST (x, Empty) = false
| searchBST (x, Node(l, parent, r)) =
if x = parent then true
else
if x< parent then searchBST(x, l)
else searchBST(x,r)
大概,這是作業。你應該使用作業標籤。 – 2012-04-02 06:13:07