Created
August 12, 2019 03:19
-
-
Save dannypsnl/2e45ede03c3fdcc742a4e3307ba6ec12 to your computer and use it in GitHub Desktop.
stalin sort XD
This file contains 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 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