【发布时间】:2012-10-04 21:18:11
【问题描述】:
我正在课堂上学习机器学习,但遇到了一个我一直坚持的家庭作业问题。昨天找了一整天,没有什么进展,课堂上也没讲这个,希望大家帮帮我。
我们得到:
datatype which = STRING of string | INT of int
第 1 部分。我们被告知需要为包含 which 类型值的二叉树创建另一个名为 whichTree 的数据类型,其中数据仅位于树的叶子上。
第 2 部分。我们需要创建一个 whichSearch 函数,其类型为 whichTree -> int -> bool,根据 int 是否在树中返回 true 或 false。
这是我目前所拥有的:
datatype which = STRING of string | INT of int;
datatype whichTree = Empty | Node of int*whichTree*whichTree;
val t1 = Node(6, Node(4,Empty,Empty), Node(15, Node(11,Empty,Empty), Node(24,Empty,Empty)));
val t2 = Node(157,Empty,Empty);
val t3 = Node(102,t1,t2);
fun whichSearch (i, Empty) = false
| whichSearch (i, Node(entry, left, right)) =
if i = entry then true
else whichSearch (i, left)
orelse whichSearch (i, right);
我现在面临的问题是这样的:
- 我的
whichTree不包含which类型。我不确定如何解决这个问题。 - 我应该拥有
whichTree -> int -> bool类型的whichSearch函数,但它是int * whichTree -> bool,并且正在努力弄清楚如何解决问题。我不确定如何解决这个问题,因为我必须在whichSearch中为i指定一个值来搜索。我正在搜索这个,但任何提示都会很棒。
有人可以帮忙吗?如果是,谢谢!并感谢那些已经回复的人。
【问题讨论】: