I need to traverse the B+ tree. If i hit a list i need to deal with it and recursively keep going till i get an element. Then i compare it to the number given. If the number is more than the greatest number in that list i can ignore that branch (list). Same for when it's less. I just need to traverse the tree and find the element. It should work no matter the tree given
This is what i did
(define ones (list '() 2 '() 4 '() 6 '() 7 '() 8 '()))
(define sixties (list '() 52 '() 54 '() 66 '() 67 '() 68 '()))
(define tens (list ones 10 '() 30 '() 50 sixties 70 '() 90 '()))
(define ninehundreds (list '() 930 '() 940 '() 960 '() 970 '() 988 '()))
(define tree (list tens 100 '() 300 '() 500 '() 700 '() 900 ninehundreds ))
(define (walk tree num)
(if list? (car tree)
(walk-list (car tree)))
(if (not list? (car tree)))
walk-list( cdr tree)
)
(define (walk-list lst)
(if (list? (car lst)) (walk-list (car lst)))
(if (not (list? (car lst))) (car lst))
)
(walk tree 0)
I have an issue with the two ifs in both defined functions. Also i kept getting back #t at one point
edit: I believe I fixed my understanding with the syntax errors. But now I get this message on the if statement in walk-list
mcar: contract violation
expected: mpair?
given: ()
(define (walk tree num)
(if (list? (car tree))
(walk-list (car tree))
(car tree))
)
(define (walk-list lst)
(if (list? (car lst))
(walk-list (car lst))
(car lst))
)
Try it at the REPL:
whereas
You can't call
caron'(). This will cause the error you're shown.