Insert element into a tree from a list in Standard ML
Posted
by vichet
on Stack Overflow
See other posts from Stack Overflow
or by vichet
Published on 2010-03-12T11:54:15Z
Indexed on
2010/03/12
11:57 UTC
Read the original article
Hit count: 443
I have just started to learn SML on my own and get stuck with a question from the tutorial. Let say I have:
tree data type
datatype node of (tree*int*tree) | null
insert function
fun insert (newItem, null) = node (null, newItem, null)
| insert (newItem, node (left, oldItem, right)) =
if (newItem <= oldItem) then node (insert(newItem,left),oldItem, right)
else
node (left, oldItem, insert(newItem, right)
an integer list
val intList = [19,23,21,100,2];
my question is how can I add write a function to loop through each element in the list and add to a tree?
Your answer is really appreciated.
© Stack Overflow or respective owner