Advertisement
jovanovski

LISP DFS

May 10th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.69 KB | None | 0 0
  1. (defun dfs (lista n max el)
  2. (cond
  3.   ;Ako e do max dlabocina, prekini
  4.   ((= n max) NIL)
  5.   ; Jazol
  6.   ((and (eq (cadr lista) NIL) (eq (caddr lista) NIL)) (eq (car lista) el))
  7.   ;Ako ima levo dete
  8.   ((and (listp (cadr lista)) (eq (caddr lista) NIL)) (dfs (cadr lista) (+ n 1) max el))
  9.   ;Ako ima desno dete
  10.   ((and (listp (caddr lista)) (eq (cadr lista) NIL)) (dfs (caddr lista)(+ n 1) max el))
  11.   ;Ako ima dve deca
  12.   ((and (listp (cadr lista)) (listp (caddr lista))) (OR (dfs (cadr lista) (+ n 1) max el) (dfs (caddr lista)  (+ n 1) max el)))
  13.   )
  14. )
  15.  
  16. ;(inorder LISTA POCETEN_BROJAC=0 MAX_DLABOCINA ELEMENT_STO_SE_BARA)
  17. (inorder '(1 (2 (3 NIL NIL)(4 NIL NIL))(5 (6 NIL NIL)(7 NIL NIL))) 0 3 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement