相关疑难解决方法(0)

OCaml中构建二叉搜索树的正确方法

好的,我已经binary search tree用 OCaml 写了一个。

type 'a bstree = 
    |Node of 'a * 'a bstree * 'a bstree
    |Leaf


let rec insert x = function
    |Leaf -> Node (x, Leaf, Leaf)
    |Node (y, left, right) as node -> 
        if x < y then
            Node (y, insert x left, right)
        else if x > y then
            Node (y, left, insert x right)
        else
            node
Run Code Online (Sandbox Code Playgroud)

上面的代码在The right way to use a data Structure in OCaml 中据说很好

然而,我发现了一个问题。这insert仅在从列表一次性构建 …

ocaml functional-programming binary-search-tree

2
推荐指数
1
解决办法
9173
查看次数