我设法让我的快速排序功能工作,但我很困惑为什么稍微更改代码导致函数表现奇怪.这是工作代码:
(defun low (mylist)
(setq result (list))
(loop
for x in mylist
do (if (< x (car mylist))
(setq result (cons x result))))
result)
(defun high (mylist)
(setq result (list))
(loop
for x in mylist
do (if (> x (car mylist))
(setq result (cons x result))))
result)
(defun qsort (mylist)
(if (null mylist)
nil
(progn
;(setq l1 (low mylist))
;(setq l2 (high mylist))
(append (qsort (low mylist))
(list (car mylist))
(qsort (high mylist))))))
Run Code Online (Sandbox Code Playgroud)
然而,在qsort功能,如果我尝试存储在分区l1和l2,然后调用 …