2

So, i am trying to find the least value of a binary search tree in racket and i keep getting this error:

cadr: contract violation expected: (cons/c any/c pair?) given: 'null

My code is the following:

(define minimum (λ (tree) (if (null? tree) null (if (null? (cadr tree)) (car tree) (minimum (cadr tree)))))

Each node has the structure (value, left, right).

1
  • Please provide proof that this isn't homework. Commented Mar 17, 2016 at 23:36

1 Answer 1

1

It looks like a problem with your test data, not the minimum procedure itself. For instance, this works for me:

(define tree
  (list 5 (list 3 (list 1 null null)
                  (list 4 null null))
          (list 6 null null)))

(minimum tree)
=> 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.