
(defn rever [a]
(defn item[l r]
(if (= nil (first l)) r
(item (rest l) (cons (first l) r))
)
)
(item a nil)
)
这段代码非常有助于理解什么是深度优先,什么是广度优先。
很久没有写习题的代码了,倒不是懒得做习题了,是私事多,状态差,做了很多题,也不想发出来
今天回复的还好,发一个。
(⊙o⊙)… 发完才发现已经发过了,把2.21也加进来吧 标题改成2.21,2.19和2.20没有存稿,我状态恢复一下再折腾。

(defn square [x](* x x))
; map 版
(defn square-list [item] (map square item))
;非map版
(defn square-list [item]
(if (empty? item)
nil
(cons
(square (first item))
(square-list (rest item))
)
)
)

这里容易出错的地方之一是,输出的内容是反序的。需要注意如何cons进序列对。











![【2024最新华为OD-C/D卷试题汇总】[支持在线评测] 卢小姐的生日礼物(200分) - 三语言AC题解(Python/Java/Cpp)](https://i-blog.csdnimg.cn/direct/794d7fc8c214456892f965eacc669f95.png)







