Created
September 15, 2016 19:16
-
-
Save joshkautz/e2186a14805b1010ca4c1545d275454b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datatype 'a Btree = Empty | Node of 'a * 'a Btree * 'a Btree; | |
fun member(x: 'a, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Empty) = false | |
| member(x: 'a, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Node(y, left, right)) = | |
if equality_relation(x,y) then true | |
else | |
if ordering_relation(x,y) then member(x, ordering_relation, equality_relation, left) | |
else member(x, ordering_relation, equality_relation, right); | |
fun insert(x, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Empty) = Node(x, Empty, Empty) | |
| insert(x, ordering_relation: 'a * 'a -> bool, equality_relation: 'a * 'a -> bool, Node(y, left, right)) = | |
if equality_relation(x,y) then Node(y, left, right) | |
else | |
if ordering_relation(x,y) then Node(y, insert(x, ordering_relation, equality_relation, left), right) | |
else Node(y, left, insert (x, ordering_relation, equality_relation, right)); | |
fun printtree(Empty, print_function: 'a -> unit ) = print "" | |
| printtree(Node(x, left, right), print_function: 'a -> unit) = printtree(left, print_function) ^ print_function(x) ^ printtree(right, print_function); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment