about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lectures/2.2/search.scm
blob: fa1d29145ed364315724ee94c506cc72e387bb5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
(define (depth-first-search tree)
  (print (datum tree))
  (for-each depth-first-search (children tree)))

(define (breadth-first-search tree)
  (bfs-iter (list tree)))

(define (bfs-iter queue)
  (if (null? queue)
      'done
      (let ((task (car queue)))
	(print (datum task))
	(bfs-iter (append (cdr queue) (children task))))))