小编use*_*517的帖子

寻找重新排列列表的算法

我一直试图找出一个能够执行以下操作的算法:

该算法将被递归如下列表:

((start a b c) (d e f (start g h i) (j k l) (end)) (end) (m n o))
Run Code Online (Sandbox Code Playgroud)

然后,它将包含元素start的列表与包含元素end的列表之前的所有列表连接起来.返回的列表应如下所示:

((start a b c (d e f (start g h i (j k l)))) (m n o))
Run Code Online (Sandbox Code Playgroud)

该算法必须能够处理包含start的其他列表中包含start的列表.

编辑:

我现在拥有的是:

(defun conc-lists (l)
  (cond
      ((endp l) '())
      ((eq (first (first l)) 'start) 
          (cons (cons (first (first l)) (conc-lists (rest (first l))))) 
              (conc-lists (rest l)))
      ((eq (first (first l)) 'end) '()) …
Run Code Online (Sandbox Code Playgroud)

algorithm list common-lisp

6
推荐指数
1
解决办法
254
查看次数

标签 统计

algorithm ×1

common-lisp ×1

list ×1