Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→Common Lisp: whitespace (parens; don't assume tabs=8); "from 0" unnecessary; use 1+, 1-; while not -> until
No edit summary |
(→Common Lisp: whitespace (parens; don't assume tabs=8); "from 0" unnecessary; use 1+, 1-; while not -> until) |
||
Line 345:
Bubble sort an sequence in-place, using the < operator for comparison if no comaprison function is provided
<lang lisp>(defun bubble-sort
"sort a sequence (array or list) with an optional comparison function (cl:< is the default)"
(loop with sorted = nil
(rotatef (elt sequence a)
(setf sorted nil)))))▼
(elt sequence (1+ a)))
<lang lisp>(bubble-sort (list 5 4 3 2 1))</lang>▼
▲(bubble-sort (list 5 4 3 2 1))
=={{header|D}}==
|