aboutsummaryrefslogtreecommitdiff
path: root/hw04_path.scm
blob: 4d404fbff06da618fe99a52cc9ba2b8ddf224bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#lang scheme

;; NAME: hw04_bintree.scm
;; AUTHOR: Ben Burwell
;; DESC: CSI310 - Programming Languages - Homework 4 - Binary Tree
;; HISTORY: Created 2013-02-11

(define path-helper
  (λ (n bst pth)
    [ (equal? (get-value bst) n) pth ]
    [ (< n (get-value bst)) (cons 'left (path-helper n (get-left bst))) ]
    [ (> n (get-value bst)) (cons 'right (path-helper n (get-right bst))) ]
    ))
    

(define path
  (λ (n bst)
    (cond
      [ (not (tree? bst)) 'not-a-tree ]
      [ else (path-helper n bst '()) ]
      )))