Skip to content

Instantly share code, notes, and snippets.

@fogus
Forked from Chouser/xset.clj
Created January 8, 2010 18:39
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 fogus/272270 to your computer and use it in GitHub Desktop.
Save fogus/272270 to your computer and use it in GitHub Desktop.
(defn xseq [t]
(when t
(concat (xseq (:l t)) [(:root t)] (xseq (:r t)))))
(defn xconj [t v]
(cond
(nil? t) {:root v :l nil :r nil}
(< v (:root t)) {:root (:root t) :l (xconj (:l t) v) :r (:r t)}
:else {:root (:root t) :l (:l t) :r (xconj (:r t) v)}))
(let [t1 (-> nil (xconj 5) (xconj 8) (xconj 3)),
t2 (xconj t1 4)]
(println "t1:" (xseq t1))
(println "t2:" (xseq t2))
(println "Do they share?" (identical? (:r t1) (:r t2))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment