Discussion:
[Lisp-cn] lisp_Iterative-deepning depth-first search问题
yxc
2015-05-11 09:30:07 UTC
Permalink
想请教䞀䞪问题
现圚写了䞀䞪凜数䞀䞪深床䌘先遍历䞀䞪广床䌘先遍历

(defun dfs (tree) 深床
(cond ((null tree) nil)
((atom tree) (cons tree nil))
(t (append (dfs (car tree))
(dfs (cdr tree))))))

Example: (dfs ‘((a (b)) c (d)) should return: (a b c d)


(defun bfs (tree)广床
(cond ((null tree) nil)
((atom (car tree)) (cons (car tree) (bfs (cdr tree))))
(t (bfs (append (cdr tree) (car tree))))))

Example: (bfs ‘((a (b)) c (d))) should return: (c a d b)

想写䞀䞪Iterative-deepning depth-first search 反倍深床遍历
蟓出应该是Example: (dfid ‘((a (b)) c(d))) should return: (c a c d a b c d)

需芁写䞀䞪计算深床的蟅助凜数

只可以䜿甚
numbers, symbols, variables
t , nil
defun, let, quote, ',
arithmetic/comparison operators : ,<=,>=,<,>,
boolean operators : and or not
List manipulation : first rest car cdr cons list append, null,
atomconditional forms
条件: if, cond,

十分感谢🙏
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”矀组。
芁退订歀矀组并停止接收歀矀组的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
yxc
2015-05-13 08:38:50 UTC
Permalink
已想出

圚 2015幎5月11日星期䞀 UTC+9䞋午6:30:07yxc写道
Post by yxc
想请教䞀䞪问题
现圚写了䞀䞪凜数䞀䞪深床䌘先遍历䞀䞪广床䌘先遍历
(defun dfs (tree) 深床
(cond ((null tree) nil)
((atom tree) (cons tree nil))
(t (append (dfs (car tree))
(dfs (cdr tree))))))
Example: (dfs ‘((a (b)) c (d)) should return: (a b c d)
(defun bfs (tree)广床
(cond ((null tree) nil)
((atom (car tree)) (cons (car tree) (bfs (cdr tree))))
(t (bfs (append (cdr tree) (car tree))))))
Example: (bfs ‘((a (b)) c (d))) should return: (c a d b)
想写䞀䞪Iterative-deepning depth-first search 反倍深床遍历
蟓出应该是Example: (dfid ‘((a (b)) c(d))) should return: (c a c d a b c d)
需芁写䞀䞪计算深床的蟅助凜数
只可以䜿甚
numbers, symbols, variables
t , nil
defun, let, quote, ',
arithmetic/comparison operators : ,<=,>=,<,>,
boolean operators : and or not
List manipulation : first rest car cdr cons list append, null,
atomconditional forms
条件: if, cond,
十分感谢🙏
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”矀组。
芁退订歀矀组并停止接收歀矀组的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
Xiaofeng Yang
2015-05-17 13:41:07 UTC
Permalink
赞~

Best regards,
Xiaofeng Yang
Post by yxc
已想出
圚 2015幎5月11日星期䞀 UTC+9䞋午6:30:07yxc写道
Post by yxc
想请教䞀䞪问题
现圚写了䞀䞪凜数䞀䞪深床䌘先遍历䞀䞪广床䌘先遍历
(defun dfs (tree) 深床
(cond ((null tree) nil)
((atom tree) (cons tree nil))
(t (append (dfs (car tree))
(dfs (cdr tree))))))
Example: (dfs ‘((a (b)) c (d)) should return: (a b c d)
(defun bfs (tree)广床
(cond ((null tree) nil)
((atom (car tree)) (cons (car tree) (bfs (cdr tree))))
(t (bfs (append (cdr tree) (car tree))))))
Example: (bfs ‘((a (b)) c (d))) should return: (c a d b)
想写䞀䞪Iterative-deepning depth-first search 反倍深床遍历
蟓出应该是Example: (dfid ‘((a (b)) c(d))) should return: (c a c d a b c d)
需芁写䞀䞪计算深床的蟅助凜数
只可以䜿甚
numbers, symbols, variables
t , nil
defun, let, quote, ',
arithmetic/comparison operators : ,<=,>=,<,>,
boolean operators : and or not
List manipulation : first rest car cdr cons list append, null,
atomconditional forms
条件: if, cond,
十分感谢[image: 🙏]
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn
---
悚收到歀邮件是因䞺悚订阅了Google眑䞊论坛䞊的“Lisp-cn(Lisp䞭文甚户组)”矀组。
芁查看曎倚选项请访问https://groups.google.com/d/optout。
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”矀组。
芁退订歀矀组并停止接收歀矀组的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
Loading...