小编sai*_*ies的帖子

Lisp中的Quicksort奇怪的行为?

我设法让我的快速排序功能工作,但我很困惑为什么稍微更改代码导致函数表现奇怪.这是工作代码:

(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功能,如果我尝试存储在分区l1l2,然后调用 …

lisp common-lisp quicksort

2
推荐指数
1
解决办法
150
查看次数

标签 统计

common-lisp ×1

lisp ×1

quicksort ×1