我有以下代码,但是当我运行此示例时:
(partition 12 '(4 9 18 6 19 10 18 11 5 5 7 2 4 19 1 9 10 18 12))
我明白了
((4 9 6 10 11 5 5 7 2 4 1 9 10 12) (18 19 18 19 18))
作为回报。
我想要它如下
((4 9 6 10 11 5 5 7 2 4 1 9 10 12) 18 19 18 19 18)
我应该怎么做才能改变这种情况?感谢支持
(require (lib "trace.ss"))
(define (partition pivot lon)
(if (null? lon)
'(()())
(let ((split-of-rest (partition pivot (cdr lon))))
(if (<= (car lon) pivot)
(list (cons (car lon) (car split-of-rest))
(cadr split-of-rest))
(list (car split-of-rest) (cons (car lon)
(car (cdr split-of-rest))))))))