Skip to content

Instantly share code, notes, and snippets.

@igordcsouza
Last active March 18, 2016 13:10
Show Gist options
  • Save igordcsouza/b71599c3baa95f9fe26f to your computer and use it in GitHub Desktop.
Save igordcsouza/b71599c3baa95f9fe26f to your computer and use it in GitHub Desktop.
Bubble sort em lisp utilizando recursividade!
(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