Skip to content

Instantly share code, notes, and snippets.

@imphasing
Created August 1, 2011 18:57
Show Gist options
  • Save imphasing/1118763 to your computer and use it in GitHub Desktop.
Save imphasing/1118763 to your computer and use it in GitHub Desktop.
(define bubblesort (lambda (l) (define swap-pass (lambda (l) (if (eq? (length l) 1) l (let ((fst (car l))(snd (cadr l))(rest (cddr l))) (if (> fst snd) (cons snd (swap-pass (cons fst rest))) (cons fst (swap-pass (cons snd rest))))))))(let for ((val l) (times (length l))) (if (> times 1) (for (swap-pass val) (- times 1)) (swap-pass val)))))
(define insertion-sort (lambda (lst) (define insert (lambda (x lst) (if (null? lst) (list x) (let ((y (car lst)) (ys (cdr lst))) (if (<= x y) (cons x lst) (cons y (insert x ys))))))) (if (null? lst) (quote ()) (insert (car lst) (insertion-sort (cdr lst))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment