私はbinary search tree
OCamlでの操作を構築しています。
type ('a, 'b) bst =
| Node of 'a * 'b * ('a, 'b) bst * ('a, 'b) bst
| Leaf;;
let rec insert k v = function
| Leaf -> Node (k, v, Leaf, Leaf)
| Node (k', v', left, right) ->
if k < k' then Node (k', v', insert k v left, right)
else if k = k' then Node (k, v, left, right)
else Node (k', v', left, insert k v right);;
let rec delete k = function
| Leaf -> Leaf
| Node (k', v, l, r) as p ->
if k < k' then Node (k', v, (delete k l),r)
else if k > k' then Node (k', v, l, (delete k r))
else
match (l, r) with
| (Leaf, Leaf) -> Leaf
| (l, Leaf) -> l
| (Leaf, r) -> r
| (_, _) ->
let Node (km, vm, _, _) = max l in
Node (km, vm, delete km l, Leaf)
私のdeletion
コードが十分であるかどうか、または改善されているかどうかを誰か教えてもらえますか?