PasteRack.org
Paste # 82025
2018-03-13 14:28:42

Fork as a new paste.

Paste viewed 283 times.


Embed:

  1. #lang racket
  2. (define t '(10 (5(4(2 ()()) (26()())) (21(15()()) (23 ()()))) (11(6()())(13()()))))
  3.  
  4. (define (leaf? t)
  5.    (and(null?(cadr t)) (null? (caddr t))))
  6.  
  7.  
  8. (define (tree-max? t)
  9.   (if (null? t)
  10.       '()
  11.       (max(cons(leaf?(car t))'())(tree-max?(caddr t)))))
  12. (tree-max? t)
  13.  
  14.  
  15. ;trying to have the leaf function go through every number in the tree until
  16. ;it get to the bottom leaves where it returns the max value of the in the tree
  17. ;im not understanding how the recursion will take place here

=>

cadr: contract violation

  expected: (cons/c any/c pair?)

  given: 10