0
能否請你幫我一個函數,我需要在樹中找到前輩,但是它會返回一個空列表,如何在不使用「set!」的情況下返回前輩。如何在Tree中找到前輩
(define (predecessor val tree)
(cond ((null? tree) (node tree)) ; If the set is null result is predecessor
((> val (node tree)) (predecessor val (right-branch tree))); if val is greater
((< val (node tree)) (predecessor val (left-branch tree))))) ; if val is lesser
(define (node tree)
(car tree))
(define (left-branch tree)
(cadr tree))
(define (right-branch tree)
(caddr tree)))
什麼是您正在測試的數據?而且我不確定你可以在第一個cond子句中得到一個空列表。 – Ivancho 2014-11-23 08:32:08