Algorithms
Logic
(ns quicksort.core) (defn quick-sort ([xs] (quick-sort xs <)) ([xs cmp] (if (seq xs) (lazy-seq (let [pivot (first xs)] (concat (quick-sort (filter #(cmp % pivot) (rest xs)) cmp) [pivot] (quick-sort (filter #(not (cmp % pivot)) (rest xs)) cmp)))) xs)))
- (ns quicksort.core)
- (defn quick-sort
([nums] (quick-sort nums <))([nums cmp] (quick-sort nums cmp nil))([nums cmp solved](if (empty? nums) solved(if (= (count nums) 1) (cons (first nums) solved)(quick-sort(filter #(cmp % (first nums)) (rest nums))cmp(cons(first nums)(quick-sort(filter #(not (cmp % (first nums))) (rest nums))cmpsolved)))))))- ([xs] (quick-sort xs <))
- ([xs cmp]
- (if (seq xs)
- (lazy-seq
- (let [pivot (first xs)]
- (concat (quick-sort (filter #(cmp % pivot) (rest xs)) cmp)
- [pivot]
- (quick-sort (filter #(not (cmp % pivot)) (rest xs)) cmp))))
- xs)))