Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. (struct tree (left value right) #:transparent)
  2.  
  3. (define (imbalance tree n)
  4. (if (null? tree)
  5. #t
  6.  
  7. (letrec ([visina (lambda (x)
  8. (cond [(null? x) 1]
  9. [(and (null? (tree-left x)) (null? (tree-right x))) 2]
  10. [(null? (tree-left x)) (+ 1 (visina (tree-right x)))]
  11. [(null? (tree-left x)) (+ 1 (visina tree-left))]
  12. [#t (+ 1 (max (visina (tree-left x)) (visina (tree-right x))))]))]
  13. [visina_levo (visina (tree-left tree))]
  14. [visina_desno (visina (tree-right tree))])
  15. (if (> (abs (- visina_levo visina_desno)) n)
  16. #f
  17. (begin (imbalance (tree-left tree) n)
  18. (imbalance (tree-right tree) n))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement