Skip to content
Merged
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ NIFR91
Michal Hanajik
<br>
Bendik Samseth
Trashtalk
Trashtalk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be possible to modify this file on Github and remove that duplicate line

18 changes: 18 additions & 0 deletions contents/bubble_sort/code/lisp/bubble_sort.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;;;;Bubble sort implementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with a line on how to run it:

;;; Run as `clisp bubble_sort.lisp`

;;;Swaps to elements in a list (complexity: O(n))
(defun swap (lst low high)
(let ((list-tail (nthcdr low lst)))
(rotatef (car list-tail) (elt list-tail (- high low)))
lst))

(defun bubble_sort (lst)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bubble_sort -> bubble-sort to be idiomatic.

(dotimes (m (- (length lst) 1) lst) ;loop
(dotimes (n (- (length lst) (+ 1 m)) lst) ;loop
(if (> (nth n lst) (nth (+ n 1) lst)) ;if
(swap lst n (+ n 1)) ;then
lst)))) ;else

;;Use of an array insead of a list would be faster
;;The built-in sort is also quicker (sort (list 5 4 3 2 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this an actual comparison:

(print (sort (list 5 4 3 2 1) #'<)))
-;;Use of an array insead of a list would be faster -;;The built-in sort is also quicker (sort (list 5 4 3 2 1)) -(print (bubble_sort (list 5 4 3 2 1))) \ No newline at end of file +;; Use of an array insead of a list would be faster +(print (bubble-sort (list 5 4 3 2 1))) +;; The built-in sort is also quicker: +(print (sort (list 5 4 3 2 1) #'<))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is insead correct word?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichalHanajik I type really fast ok ;)

(print (bubble_sort (list 5 4 3 2 1)))