Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 (define-struct node (left right))
6 A binary-tree (bt) is either
7 1. empty or
8 2. (make-node l r)
9 where l,r are binary-trees (bt).
11 height : bt -> number
12 Determines the height (depth) of a binary tree.
14 (define (height abt)
15 (cond
16 [(empty? abt) 0]
17 [else (+ (max (height (node-left abt))
18 (height (node-right abt)))
19 1)]))