home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0963.lha / SIOD / scm / bubblesort.scm < prev    next >
Text File  |  1993-02-22  |  630b  |  16 lines

  1. (define (bubble-sort l test)
  2.         (let ((changes #t)
  3.               (l1 l)
  4.               (tmp nil))
  5.              (while changes 
  6.                     (set! changes #f)
  7.                     (while (not (null? (cdr l1)))
  8.                            (if (test (car l1) (cadr l1))
  9.                                (begin (set! tmp (car l1))
  10.                                       (set-car! l1 (cadr l1))
  11.                                       (set-car! (cdr l1) tmp)
  12.                                       (set! changes #t)))
  13.                            (gc)
  14.                            (set! l1 (cdr l1)))
  15.                     (set! l1 l))))
  16.