Skip to content

Instantly share code, notes, and snippets.

@kosugi
Created July 1, 2012 04:14
Show Gist options
  • Select an option

  • Save kosugi/3026797 to your computer and use it in GitHub Desktop.

Select an option

Save kosugi/3026797 to your computer and use it in GitHub Desktop.
breadth-first-search
(define (bfs tree)
(if (not (null? tree))
(let loop ((p (list tree)) (q '()))
(if (null? p)
(if (not (null? q))
(loop q '()))
(begin
(display (caar p))
(newline)
(loop (cdr p) (append q (cdar p))))))))
(bfs '(1 (2 (4 (9)) (5) (6)) (3 (7 (10) (11) (12)) (8 (13 (14))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment