[ create a new paste ] login | about

Link: http://codepad.org/aYK2UmdY    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Oct 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; pessimal algorithms and simplexity analysis

(define (slowsort a i j)
  (when (< i j)
    (let ((m (quotient (+ i j) 2)))
      (slowsort a i m)
      (slowsort a (+ m 1) j)
      (when (> (vector-ref a m) (vector-ref a j))
        (let ((t (vector-ref a m)))
          (vector-set! a m (vector-ref a j))
          (vector-set! a j t)))
      (slowsort a i (- j 1)))))

(define x (vector 4 6 7 1 5 2 3))
(display x) (newline)
(slowsort x 0 6)
(display x) (newline)


Output:
1
2
#(4 6 7 1 5 2 3)
#(1 2 3 4 5 6 7)


Create a new paste based on this one


Comments: