how to find predecessor in the tree

Discussion of Scheme and Racket

how to find predecessor in the tree

Postby Lulu » Sat Nov 22, 2014 1:43 pm

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
    )
 )
Lulu
 
Posts: 1
Joined: Tue Nov 18, 2014 8:10 am

Return to Scheme

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron