(define-structure (tree-empty)) (define-structure (tree-branch value l r)) (define emptytree (make-tree-empty)) (define exampletree (make-tree-branch 30 (make-tree-branch 20 (make-tree-branch 10 emptytree emptytree) emptytree) (make-tree-branch 15 (make-tree-branch 40 emptytree (make-tree-branch 14 emptytree emptytree)) (make-tree-branch 70 (make-tree-branch 8 emptytree emptytree) emptytree)))) (define-structure (path-none)) (define-structure (path-empty)) (define-structure (path-some value rest)) (define nopath (make-path-none)) (define emptypath (make-path-empty)) ; given: a value, a binary tree, a path so far to get to this tree ; returns: false if the value is not in the tree ; the path to the value if the value is in the tree (define depth-first-search (lambda (value tree path) (cond ((tree-empty? tree) nopath) ((eq? value (tree-branch-value tree)) (make-path-some (tree-branch-value tree) path)) (else ((lambda (path-l) (if (path-none? path-l) (depth-first-search value (tree-branch-r tree) (make-path-some (tree-branch-value tree) path)) path-l)) (depth-first-search value (tree-branch-l tree) (make-path-some (tree-branch-value tree) path))))))) (depth-first-search 14 exampletree emptypath)