ツリーを作成しました
type 'a tree = {
mutable cont: 'a;
mutable left: 'a bin_tree;
mutable right: 'a bin_tree
}
and 'a bin_tree =
Empty
| Node of 'a tree;;
そして、私は次のようないくつかの単純な機能を実行するのに苦労しています
- 要素の挿入 (適切なサブツリーへ、重複なし)
- 2 つの二分木の和集合を作る
私は自分の問題をグーグルで検索しましたが、常にエラーが発生しています。例えば:
let rec insert x tree =
match tree with
Empty -> Node(x, Empty, Empty)
| Node(y, left, right) ->
if x <= y then Node(y, insert x left, right)
else Node(y, left, insert x right)
または私が試してみると:
let rec insert x = function
Empty -> Node(Empty, x, Empty)
| Node(lb, r, rb) -> if x < r then Node(insert x lb, r, rb)
else Node{lb; r; insert x rb} ;;
常に構文エラーが発生します。