Skip to content

Instantly share code, notes, and snippets.

@viksit
Created June 8, 2010 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viksit/aa0a0095fe386f490b6f to your computer and use it in GitHub Desktop.
Save viksit/aa0a0095fe386f490b6f to your computer and use it in GitHub Desktop.
(defn queue [& xs]
(when (seq xs)
(apply conj clojure.lang.PersistentQueue/EMPTY xs)))
(defn level-order [rootnode]
(loop [curlevel (queue rootnode)]
(when-not (empty? curlevel)
(if-let [n (first curlevel)]
(do
(prn (peek curlevel))
(prn (n :value))
(recur (conj (pop curlevel) (n :left) (n :right))))
(recur (pop curlevel))))))
(level-order mytree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment