Last active
March 18, 2016 13:10
-
-
Save igordcsouza/b71599c3baa95f9fe26f to your computer and use it in GitHub Desktop.
Bubble sort em lisp utilizando recursividade!
This file contains hidden or 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 change(lat x) | |
(setq Aux (nth x lat)) | |
(setf (nth x lat) (nth (+ 1 x) lat)) | |
(setf (nth (+ 1 x) lat) Aux)) | |
(defun bubble(lat x y) | |
(if(= x (length lat)) | |
(print lat) | |
(cond((< y (length lat)) | |
(cond((not (null (nth (+ 1 y) lat))) | |
(if (> (nth y lat) (nth (+ 1 y) lat)) | |
(change lat y)))) | |
(bubble lat x (+ 1 y))) | |
((= y (length lat)) | |
(bubble lat (+ 1 x) 0))))) | |
(bubble '(3 1 8 2 32 12 98 73 111 623 5 35) 0 0) | |
(bubble '() 0 0) | |
(bubble '(1) 0 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment