上邊的這個太慢了。改成這樣就很快了
(define bubble
(lambda (predicate b slst)
(if (null? slst)
(list b)
(if (predicate (car slst) b)
(let ((bu-ret (bubble predicate (car slst) (cdr slst))))
(cons (car bu-ret) (cons b (cdr bu-ret))))
(let ((bu-ret (bubble predicate b (cdr slst))))
(cons (car bu-ret) (cons (car slst) (cdr bu-ret))))))))
;Value: bubble
(define sort
(lambda (predicate lon)
(if (null? lon)
'()
(let ((bu-ret (bubble predicate (car lon) (cdr lon))))
(cons (car bu-ret) (sort predicate (cdr bu-ret)))))))
;Value: sort
(sort < '(1 26 8 2 35 897 45 97 425 90 34 87 76 46 38 82 7 58 8 48 231 85 15 700 358 0 63 78 4174 896 41 32))
;Value 11: (0 1 2 7 8 8 15 26 32 34 35 38 41 45 46 48 58 63 76 78 82 85 87 90 97 231 358 425 700 896 897 4174)
(sort > '(1 26 8 2 35 897 45 97 425 90 34 87 76 46 38 82 7 58 8 48 231 85 15 700 358 0 63 78 4174 896 41 32))
;Value 12: (4174 897 896 700 425 358 231 97 90 87 85 82 78 76 63 58 48 46 45 41 38 35 34 32 26 15 8 8 7 2 1 0)