Page 1 of 1

how to find predecessor in the tree

Posted: Sat Nov 22, 2014 1:43 pm
by Lulu
Hello, Could you help me with a function, I need to find the predecessor in the tree, but my function always returns an empty list,

Code: Select all

(define (predecessor element tree)
   (cond
        ((null? tree) (node tree) ) ; If the tree is null result is  the needed element
        ((> element (node tree)) (mem element (right-branch tree))); if the element is greater than node element, we search it in the right-branch tree
        ((< element (node tr)) (mem element (left-branch tree))) ; if element is lesser than node element, we search it in the left-branch tree
    )
 )