Created
July 18, 2010 18:53
-
-
Save raek/480615 to your computer and use it in GitHub Desktop.
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
(defn breadth-first-traversal | |
([g start] | |
(breadth-first-traversal g [start] [[] #{}])) | |
([g queue [path visited]] | |
(if (seq queue) | |
(let [node (first queue) | |
next (remove visited (neighbors g node))] | |
(lazy-seq (breadth-first-traversal g (into (subvec queue 1) next) | |
[(conj path node) | |
(into (conj visited node) next)]))) | |
path))) | |
(defn breadth-first-traversal | |
([g start] | |
(breadth-first-traversal g [start] #{})) | |
([g queue visited] | |
(lazy-seq | |
(if (seq queue) | |
(let [node (first queue) | |
next (remove visited (neighbors g node))] | |
(cons node (breadth-first-traversal g (into (subvec queue 1) next) | |
(into (conj visited node) next)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment