#lang racket
;; A tree-of-X is either
;; - #f
;; - (node X num tree-of-X tree-of-X)
(struct node (val height left right) #:transparent)
;; ----------------------------------------
(define (tree-height t)
(cond
[(not t) 0]
[else (node-height t)]))
(define (combine val left right)
(node val
(add1 (max (tree-height left) (tree-height right)))
left
right))
(define (reverse-combine val right left)
(combine val left right))
;; ----------------------------------------
;; insert : tree X (X X -> bool) -> tree
(define (insert t val bool)
;; (tree-of-X -> tree-of-X)
;; (tree-of-X -> tree-of-X)
;; (X tree-of-X tree-of-X -> tree-of-X)
;; -> tree
;; Like insert, but inserts to a child, where `node-to'
;; determines the side where the child is added,`node-other'
;; is the other side, and `comb' builds the new tree gven the
;; two new children.
(define (insert-to t new-val