【发布时间】:2014-05-18 06:58:44
【问题描述】:
标题说了很多,这就是功能:
optimistic: dtree -> int * (int list)
let rec optimistic dt =
match dt with
| Decision(choiceL, costL, l, choiceR, costR, r) ->
if costL > costR then 0::xs; optimistic r - costR
else 1::xs ; optimistic l - costL
| Chance(eventL, probL, l, eventR, probR, r) ->
if optimistic l > optimistic r then 0::xs ; optimistic l
else 1::xs ; optimistic r
| Outcome -> value, x
;;
基本上,根据我们取下二叉树的“路线”,我们将通过使用 0(左转时)或 1(右转时)记录该路径并将这些数字一起组成一个列表,我们将在最后返回。
问题是,我想不出一种方法让这个列表通过递归持续存在,因为它没有被当作参数。任何想法如何做这样的事情?
【问题讨论】:
标签: list recursion tree ocaml binary-tree