Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created June 8, 2010 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michalmarczyk/429607 to your computer and use it in GitHub Desktop.
Save michalmarczyk/429607 to your computer and use it in GitHub Desktop.
(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