;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname bst) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))))) ;; a node of a binary search tree ;; ssn is an integer representing a social security number ;; name is a symbol representing a name ;; left and right are nodes for left and right subtree (define-struct node (ssn name left right)) ;; define the rest of the tree A (define mytree (make-node 63 'a (make-node 29 'b (make-node 15 'c (make-node 10 'd false false) (make-node 24 'e false false)) false) (make-node 89 'i false false))) ;; search-bt: integer, binary tree node -> symbol/boolean ;; The function consumes a number n and a binary tree node. ;; If the tree contains a node structure whose ssn field is n, ;; the function produces the value of the name field in that node. ;; Otherwise, the function produces false. ;; inorder: binary tree node -> a list of integers ;; It consumes a binary tree and produces a list of all the ssn numbers ;; in the tree. The list contains the numbers in the left-to-right order: ;; the numbers in the left subtree, the number in the node, the ;; numbers in the right subtree (define (inorder a-node) (cond [(false? a-node) empty] [else (append (inorder (node-left a-node)) (list (node-ssn a-node)) (inorder (node-right a-node)) )] ) ) (inorder false) (inorder mytree)