Hello,
I am trying to traverse the list (A (B (D E) C)) in a way that the print output should be in the following order D, E, B, C, A aka depth first traversal.
So far, I have come up with this code but it seems to have some strange problem.
I am trying to traverse the list (A (B (D E) C)) in a way that the print output should be in the following order D, E, B, C, A aka depth first traversal.
So far, I have come up with this code but it seems to have some strange problem.
(setq start (list 'a (list 'b (list 'd 'e) 'c ))) ====> gives ====> (A (B (D E) C))
(defun depth-first (start)
(cond
((null start) 0)
((listp (first start)) (setq start (first start))
(depth-first (first start)))
((not (eq nil (car start))) (print (car start))
(setq start (rest start))
(depth-first (start)))
(t "Go home")))
Can someone please help me out.