Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→{{header|Pascal}}: simplify the code.) |
No edit summary |
||
Line 19: | Line 19: | ||
* The article on [[wp:Bubble_sort|Wikipedia]]. |
* The article on [[wp:Bubble_sort|Wikipedia]]. |
||
* Dance [http://www.youtube.com/watch?v=lyZQPjUT5B4&feature=youtu.be interpretation]. |
* Dance [http://www.youtube.com/watch?v=lyZQPjUT5B4&feature=youtu.be interpretation]. |
||
=={{header|ACL2}}== |
|||
<lang Lisp>(defun bubble (xs) |
|||
(if (endp (rest xs)) |
|||
(mv nil xs) |
|||
(let ((x1 (first xs)) |
|||
(x2 (second xs))) |
|||
(if (> x1 x2) |
|||
(mv-let (_ ys) |
|||
(bubble (cons x1 (rest (rest xs)))) |
|||
(declare (ignore _)) |
|||
(mv t (cons x2 ys))) |
|||
(mv-let (has-changed ys) |
|||
(bubble (rest xs)) |
|||
(mv has-changed (cons x1 ys))))))) |
|||
(defun bsort-r (xs limit) |
|||
(declare (xargs :measure (nfix limit))) |
|||
(if (zp limit) |
|||
xs |
|||
(mv-let (has-changed ys) |
|||
(bubble xs) |
|||
(if has-changed |
|||
(bsort-r ys (1- limit)) |
|||
ys)))) |
|||
(defun bsort (xs) |
|||
(bsort-r xs (len xs)))</lang> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |