10 lines
268 B
Scheme
10 lines
268 B
Scheme
|
(define (insert pred item ls)
|
||
|
(if (or (null? ls) (pred item (car ls)))
|
||
|
(cons item ls)
|
||
|
(cons (car ls) (insert pred item (cdr ls)))))
|
||
|
|
||
|
(define (sort pred todo done)
|
||
|
(if (null? todo)
|
||
|
done
|
||
|
(sort pred (cdr todo) (insert pred (car todo) done))))
|