Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,9 +1,9 @@
|
|||
#lang racket
|
||||
(define (quicksort a-list (compare <))
|
||||
(match a-list
|
||||
((list)
|
||||
(list))
|
||||
((cons x xs)
|
||||
(append (quicksort (filter (lambda (element) (compare element x)) xs) compare)
|
||||
(list x)
|
||||
(quicksort (filter (lambda (element) (not (compare element x))) xs) compare)))))
|
||||
(define (quicksort < l)
|
||||
(match l
|
||||
['() '()]
|
||||
[(cons x xs)
|
||||
(let-values ([(xs-gte xs-lt) (partition (curry < x) xs)])
|
||||
(append (quicksort < xs-lt)
|
||||
(list x)
|
||||
(quicksort < xs-gte)))]))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
(quicksort '(8 7 5 6 4 3 2))
|
||||
(quicksort < '(8 7 3 6 4 5 2))
|
||||
;returns '(2 3 4 5 6 7 8)
|
||||
(quicksort '("Quicksort" "Mergesort" "Bubblesort") string<?)
|
||||
(quicksort string<? '("Mergesort" "Quicksort" "Bubblesort"))
|
||||
;returns '("Bubblesort" "Mergesort" "Quicksort")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue