Skip to content

Instantly share code, notes, and snippets.

@viksit
Forked from michalmarczyk/gist:429607
Created June 8, 2010 04:13
Show Gist options
  • Save viksit/429608 to your computer and use it in GitHub Desktop.
Save viksit/429608 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