All pastes #92321 Raw Edit

Insert-sort

public text v1 · immutable
#92321 ·published 2006-07-19 13:26 UTC
rendered paste body
(defun insert(value sorted-list comparison-fn)
  (if (equal sorted-list ())
      (cons value nil)
    (if (funcall comparison value (car sorted-list))
      (cons value sorted-list)
    (cons (car sorted-list) 
          (insert value (cdr sorted-list) comparison)))))

(defun insert-sort(unsorted-list comparison)
  "Insert Sort, takes a list and a function that can compare the items in the list"
  (if (not (equal unsorted-list ()))
      (insert (car unsorted-list)
              (insert-sort (cdr unsorted-list) comparison)
              comparison)))