Last active
August 29, 2015 14:04
-
-
Save kanatzidis/97c464e7b2595a614ed9 to your computer and use it in GitHub Desktop.
Bubble sort without side effects (an embarrassingly bad way of doing it)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my-bubble (lst) | |
(or (not lst) | |
(let ((ret nil) (iter nil) (small (reduce (lambda (x y) (min x y)) lst))) | |
(dolist (obj lst) | |
(if (not (eql obj small)) | |
(setf iter (cons obj iter)) | |
(setf ret (append ret (cons obj nil))))) | |
(append ret (let ((a (my-bubble iter))) (and (listp a) a)))))) | |
(my-bubble '(1 4 3 8 2 9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment