Created
August 1, 2011 18:57
-
-
Save imphasing/1118763 to your computer and use it in GitHub Desktop.
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
(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