Created
December 25, 2015 11:41
-
-
Save TheOpenDevProject/37a9d4b4772b15c26faf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
functor BFS (structure Q: QUEUE) = (* after Okasaki, ICFP, 2000 *) | |
struct | |
datatype 'a tree | |
= E | |
| T of 'a * 'a tree * 'a tree | |
fun bfsQ (q : 'a tree Q.queue) : 'a list = | |
if Q.isEmpty q then [] | |
else let | |
val (t, q') = Q.remove q | |
in case t | |
of E => bfsQ q' | |
| T (x, l, r) => let | |
val q'' = Q.insert (r, Q.insert (l, q')) | |
in | |
x :: bfsQ q'' | |
end | |
end | |
fun bfs t = bfsQ (Q.singleton t) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment