Created
June 8, 2010 04:11
-
-
Save michalmarczyk/429607 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
(defn level-order [f tree] | |
(loop [to-do [tree]] | |
(if (empty? to-do) | |
:done | |
(do (dorun (map (comp f :value) to-do)) | |
(recur (mapcat (fn [{:keys [left right]}] (remove nil? [left right])) | |
to-do)))))) | |
(level-order println | |
{:value 1 | |
:left {:value 2 | |
:left {:value 4} | |
:right {:value 5}} | |
:right {:value 3 | |
:left {:value 6} | |
:right {:value 7}}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment