sync from Atlas
This commit is contained in:
17
02-array-seq/lispy/py3.10/quicksort.scm
Normal file
17
02-array-seq/lispy/py3.10/quicksort.scm
Normal file
@@ -0,0 +1,17 @@
|
||||
(define (quicksort lst)
|
||||
(if (null? lst)
|
||||
lst
|
||||
(begin
|
||||
(define pivot (car lst))
|
||||
(define rest (cdr lst))
|
||||
(append
|
||||
(quicksort
|
||||
(filter (lambda (x) (< x pivot)) rest))
|
||||
(list pivot)
|
||||
(quicksort
|
||||
(filter (lambda (x) (>= x pivot)) rest)))
|
||||
)
|
||||
)
|
||||
)
|
||||
(display
|
||||
(quicksort (list 2 1 6 3 4 0 8 9 7 5)))
|
||||
Reference in New Issue
Block a user