daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 62 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. (3)
  2.   (2)    ()
  3. ()  ()
  4.    
  5. (3)
  6.   (2)    (4)
  7. ()  ()  () ()
  8.    
  9. #lang racket
  10.  
  11. (define (left tree)
  12.   (list-ref tree 0)
  13.   )
  14. (define (value tree)
  15.   (list-ref tree 1)
  16.   )
  17. (define (right tree)
  18.   (list-ref tree 2)
  19.   )
  20. (define (merge left value right)
  21.   (append (cons left '()) (append (cons value '()) (cons right '())))
  22.   )
  23. (define (insert tree n)
  24.   (cond
  25.     [(empty? tree) (append '(()) (cons n '()) '(()))] ; leaf
  26.     [(> (value tree) n) (merge (insert (left tree) n) (value tree)(right tree))] ; internal - go left
  27.     [(< (value tree) n) (merge (left tree) (value tree) (insert (right tree) n))] ; internal - go right
  28.     [(eq? (value tree) n) tree] ; internal - n already in tree
  29.     )
  30.   )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top