all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
(define (merge-sort l gt?)
|
||||
(define (merge left right)
|
||||
(cond
|
||||
((null? left)
|
||||
right)
|
||||
((null? right)
|
||||
left)
|
||||
((gt? (car left) (car right))
|
||||
(cons (car right)
|
||||
(merge left (cdr right))))
|
||||
(else
|
||||
(cons (car left)
|
||||
(merge (cdr left) right)))))
|
||||
(define (take l n)
|
||||
(if (zero? n)
|
||||
(list)
|
||||
(cons (car l)
|
||||
(take (cdr l) (- n 1)))))
|
||||
(let ((half (quotient (length l) 2)))
|
||||
(if (zero? half)
|
||||
l
|
||||
(merge (merge-sort (take l half) gt?)
|
||||
(merge-sort (list-tail l half) gt?)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue