Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
llmergesort, midpoint, and dmerj
(defun midpoint (lst)
(setq current lst)
(setq prev lst)
(loop while (and lst (rest lst)) do
(setq lst (rest (rest lst)))
(setq prev current)
(setq current (rest current)))
(defun dmerj (x y)
((not x) y)
((not y) x)
(if (< (first x) (first y))
(setq front x)
(setq x (rest x)))
(setq front y)
(setq y (rest y))))
(setq end front)
(loop while x do
(if (or (not y) (< (first x) (first y)))
(setf (rest end) x)
(setq x (rest x)))
(setf (rest end) y)
(setq y (rest y))))
(setq end (rest end)))
(setf (rest end) y)
(defun llmergesort (lst)
(let (mid half)
(if (or (not lst) (not (rest lst)))
(setq mid (midpoint lst))
(setq half (rest mid))
(setf (rest mid) nil)
(dmerj (llmergesort lst)
(llmergesort half))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment