Skip to content

Instantly share code, notes, and snippets.

@dannypsnl
Created August 12, 2019 03:19
Show Gist options
  • Save dannypsnl/2e45ede03c3fdcc742a4e3307ba6ec12 to your computer and use it in GitHub Desktop.
Save dannypsnl/2e45ede03c3fdcc742a4e3307ba6ec12 to your computer and use it in GitHub Desktop.
stalin sort XD
(defun stalin-sort (list)
(let ((cur (car list))
(rest (cdr list)))
(cond
;; [] leads []
((null rest) list)
;; e.g [3, 2, 4] => cur: 3, rest [2, 4], since 3 > 2 = car([2, 4])
;; keep run the sort by current filter
((> cur (car rest))
(stalin-sort (cons cur (cdr rest))))
;; else just return the list by cur concat with rest after sort
(t (cons cur (stalin-sort rest))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment