1
的整個列表我有這樣的代碼添加整數二叉樹F#
type Tree<'T when 'T: comparison> =
| Empty
| Node of 'T * Tree<'T> * Tree<'T>
let rec insert value = function
| Empty -> Node(value, Empty, Empty)
| Node(v, left, right) when value < v -> Node(v, insert value left, right)
| Node(v, left, right) when value > v -> Node(v, left, insert value right)
| Node(_, _, _) as n -> n
但insteed增加一個整數的我想補充整數的整個列表。例如:
let tree = addList [5;2;1;6;7];;
和清單應添加到樹
不錯,有沒有辦法做到這一點,沒有任何內置功能? – user1838768
您可以重新發明輪子並編寫您自己的List.fold版本。看看[這裏](http://en.wikibooks.org/wiki/F_Sharp_Programming/Lists#List.fold_and_List.foldBack) – Panos
該代碼給出了錯誤:缺少函數體 – user1838768