Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (in-ns 'user)
- (defn sort-parts
- "Lazy, tail-recursive, incremental quicksort. Works against
- and creates partitions based on the pivot, defined as 'work'."
- [work]
- (lazy-seq
- (loop [[part & parts] work]
- (if-let [[pivot & xs] (seq part)]
- (let [smaller? #(< % pivot)]
- (recur (list*
- (filter smaller? xs)
- pivot
- (remove smaller? xs)
- parts)))
- (when-let [[x & parts] parts]
- (cons x (sort-parts parts)))))))
- (defn qsort [xs]
- (sort-parts (list xs)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement