This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,14 @@
#lang racket
(define (shell-sort! xs)
(define (ref i) (vector-ref xs i))
(define (new Δ) (if (= Δ 2) 1 (exact-floor (/ (* Δ 5) 11))))
(let loop ([Δ (quotient (vector-length xs) 2)])
(unless (= Δ 0)
(for ([xi (in-vector xs)] [i (in-naturals)])
(let while ([i i])
(cond [(and (>= i Δ) (> (ref (- i Δ)) xi))
(vector-set! xs i (ref (- i Δ)))
(while (- i Δ))]
[(vector-set! xs i xi)])))
(loop (new Δ))))
xs)