Skip to content

Commit 2cd42ee

Browse files
changed remove procedure defination
1 parent 5afe23c commit 2cd42ee

File tree

1 file changed

+15
-2
lines changed
  • selection-sort/src/selection_sort

1 file changed

+15
-2
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
(ns selection-sort.core
22
(:gen-class))
33

4+
(defn remov
5+
[x args]
6+
(filter (fn [y] (not= x y)) args))
7+
48
(defn isort
59
[arg]
610
(loop [sorted-list []
711
unsorted-list arg]
812
(if (empty? unsorted-list)
913
sorted-list
10-
(recur (cons (apply min unsorted-list) sorted-list)
11-
(remove (fn [x] (= x (apply min unsorted-list))) unsorted-list)))))
14+
(let [minimum (apply min unsorted-list)]
15+
(recur (cons minimum sorted-list)
16+
(remov minimum unsorted-list))))))
1217

1318
(defn -main
1419
[& args]
1520
(println (isort (map read-string args))))
1621

22+
23+
;; clojure primitive procedure, remove
24+
1725
;; => (remove (fn[x] (= x 3)) '(1 2 3 4 5))
1826
;; (1 2 4 5)
27+
28+
;; above self defined procedure, remov
29+
30+
;; => (remov 3 '(1 2 3 4 5))
31+
;; (1 2 4 5)

0 commit comments

Comments
 (0)