all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
(define (split-by l p k)
|
||||
(let loop ((low '())
|
||||
(high '())
|
||||
(l l))
|
||||
(cond ((null? l)
|
||||
(k low high))
|
||||
((p (car l))
|
||||
(loop low (cons (car l) high) (cdr l)))
|
||||
(else
|
||||
(loop (cons (car l) low) high (cdr l))))))
|
||||
|
||||
(define (quicksort l gt?)
|
||||
(if (null? l)
|
||||
'()
|
||||
(split-by (cdr l)
|
||||
(lambda (x) (gt? x (car l)))
|
||||
(lambda (low high)
|
||||
(append (quicksort low gt?)
|
||||
(list (car l))
|
||||
(quicksort high gt?))))))
|
||||
|
||||
(quicksort '(1 3 5 7 9 8 6 4 2) >)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(define (quicksort l gt?)
|
||||
(if (null? l)
|
||||
'()
|
||||
(append (quicksort (filter (lambda (x) (gt? (car l) x)) (cdr l)) gt?)
|
||||
(list (car l))
|
||||
(quicksort (filter (lambda (x) (not (gt? (car l) x))) (cdr l)) gt?))))
|
||||
|
||||
(quicksort '(1 3 5 7 9 8 6 4 2) >)
|
||||
Loading…
Add table
Add a link
Reference in a new issue