その他のソート
ソース
(use srfi-43)
(define (selection-sort ls)
(define (vector-min-index vect start-index)
(do ((i start-index (+ i 1))
(min-value +inf.0)
(min-index 0))
((= i (vector-length vect))(values min-index min-value))
(when (< (vector-ref vect i) min-value)
(set! min-value (vector-ref vect i))
(set! min-index i))))
(do ((i 0 (+ i 1))
(vect (list->vector ls)))
((= i (length ls))(vector->list vect))
(vector-swap! vect i (vector-min-index vect i))))
(use gauche.sequence)
(define (test sorter n)
(for-each (^i (let1 ls (shuffle (iota (expt 10 i)))
(print "; length = " (expt 10 i))
(time (sorter ls))
(print)))
(iota n 2)))
(test selection-sort 4)
0 件のコメント:
コメントを投稿