Created
July 25, 2016 01:06
-
-
Save winny-/3769578bd48b0b873785917988eae9a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#lang racket | |
(define (is ls) | |
(let loop ([ls ls] [acc '()]) | |
(if (empty? ls) | |
acc | |
(loop (cdr ls) (ins acc (car ls)))))) | |
(define (ins ls elem) | |
(if (or (empty? ls) (< elem (car ls))) | |
(cons elem ls) | |
(cons (car ls) (ins (cdr ls) elem)))) | |
(module+ test | |
(require rackunit) | |
(define tests | |
'(((1 2 3 4) . (1 2 3 4)) | |
((5 4 3 2) . (2 3 4 5)) | |
((9 7 8 2) . (2 7 8 9)))) | |
(for ([t tests]) | |
(check-equal? (is (car t)) (cdr t)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment