-
- Notifications
You must be signed in to change notification settings - Fork 359
Added Lisp implementation for bubble sort #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ba85d61 492826d e70f287 db9f929 05c3caa 7681e94 3de5654 2226a8c c08f07d 5556912 ffbc7ab 3ee257f cc914ad bdfb8bc File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -57,3 +57,5 @@ NIFR91 | |
| Michal Hanajik | ||
| <br> | ||
| Bendik Samseth | ||
| Trashtalk | ||
| Trashtalk | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ;;;;Bubble sort implementation | ||
| ||
| | ||
| ;;;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) | ||
| ||
| (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)) | ||
| ||
| (print (bubble_sort (list 5 4 3 2 1))) | ||
There was a problem hiding this comment.
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