Created
October 26, 2012 21:41
-
-
Save ddeaguiar/3961734 to your computer and use it in GitHub Desktop.
clojure exercise
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
(def tree [:f [:b [:a nil nil] [:d [:c nil nil] [:e nil nil]]] [:g nil [:i [:h nil nil] nil]]]) | |
(fact | |
(depth-first-preorder tree) => [:f :b :a :d :c :e :g :i :h]) | |
;cheating? =) | |
(defn depth-first-preorder | |
"Perform a preorder traversal of a tree, depth-first." | |
[tree] | |
(filter #(not (nil? %)) (flatten tree))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment