Jump to content

Sorting algorithms/Quicksort: Difference between revisions

+Scheme
m (Added to <20 category)
(+Scheme)
Line 326:
return qsort([y for y in L if y <= pivot]) + [y for y in L if y == pivot] + \
qsort([y for y in L if y > pivot])
 
=={{header|Scheme}}==
(define (split-by l p)
(let loop ((low (list)) (high (list)) (l l))
(if (null? l)
(cons low high)
(if (p (car l))
(loop low (cons (car l) high) (cdr l))
(loop (cons (car l) low) high (cdr l))))))
(define (quicksort l gt?)
(let q ((l l))
(if (null? l)
l
(let ((s (split-by (cdr l) (lambda (x) (gt? x (car l))))))
(append (q (car s)) (list (car l)) (q (cdr s)))))))
 
(quicksort (list 1 3 5 7 9 8 6 4 2) >)
 
=={{header|Seed7}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.