fork download
  1. ; gnome sort
  2.  
  3. (define (gnome-sort lt? xs)
  4. (let loop ((behind (list)) (before xs))
  5. (display behind) (display " ")
  6. (display before) (newline)
  7. (cond ((null? before)
  8. (reverse behind))
  9. ((null? behind)
  10. (loop (list (car before))
  11. (cdr before)))
  12. ((lt? (car behind) (car before))
  13. (loop (cons (car before) behind)
  14. (cdr before)))
  15. (else (loop (cdr behind)
  16. (cons (car before)
  17. (cons (car behind)
  18. (cdr before))))))))
  19.  
  20. (display (gnome-sort < '(4 1 2 5 3))) (newline)
Success #stdin #stdout 0.03s 8616KB
stdin
Standard input is empty
stdout
() (4 1 2 5 3)
(4) (1 2 5 3)
() (1 4 2 5 3)
(1) (4 2 5 3)
(4 1) (2 5 3)
(1) (2 4 5 3)
(2 1) (4 5 3)
(4 2 1) (5 3)
(5 4 2 1) (3)
(4 2 1) (3 5)
(2 1) (3 4 5)
(3 2 1) (4 5)
(4 3 2 1) (5)
(5 4 3 2 1) ()
(1 2 3 4 5)