Skip to content

Instantly share code, notes, and snippets.

@winny-
Created July 25, 2016 01:06
Show Gist options
  • Save winny-/3769578bd48b0b873785917988eae9a2 to your computer and use it in GitHub Desktop.
Save winny-/3769578bd48b0b873785917988eae9a2 to your computer and use it in GitHub Desktop.
#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