HB <hubaghd...@gmail.com> writes: > I'm trying to implement searching algorithm for binary tree. > > (defrecord Node [data left-child right-child]) > > (defrecord Tree [root]) > > (defn find-node [tree data] > "Search for a node" > (let [root (:root tree)] > (loop [current root] > (if (= data (:data current)) > current > (cond > (< data (:data current)) > (> data (:data current))))))) > > I don't know to to set/assign a value for current inside cond form. > Thank you for help and time.
loop should be paired with recur. So something like this (untested): (defn find-node [tree data] "Search for a node" (loop [current (:root tree)] (cond (nil? current) nil (< data (:data current)) (recur (:left-child current)) (> data (:data current)) (recur (:right-child current)) :else current))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en