[ prog / sol / mona ]

prog


Merge sort in Scheme

1 2023-10-11 17:51

I wrote merge sort in Scheme

(define (merge l1 l2)
  (cond ((null? l1) l2)
        ((null? l2) l1)
        ((< (car l1) (car l2)) (cons (car l1) (merge (cdr l1) l2)))
        (else (cons (car l2) (merge l1 (cdr l2))))))

(define (merge-sort l)
  (cond ((null? l) '())
        (else (merge (list (car l)) (merge-sort (cdr l))))))
8


VIP:

do not edit these