Schema - Binary Tree Display

I am completely starting my career in Scheme and for the past few days I have been struggling with a problem in code. My task is to write a function that displays a binary tree. This is what I have done so far:

(define (get-pair t) (list (list-ref t 0) (list-ref t 1)))
(define (get-left t) (cadr t))
(define (get-right t) (caddr t))
    (define (print-tree tree) 
      (if (not (null? tree))       
       (begin
          (print-tree (get-left tree))
          (display (get-pair tree))
          (print-tree (get-right tree))
        )
       )
    ) 

      

Unfortunately, due to functional programming rules, I cannot use the "list-ref" command (like "append", "list tail", "vector", etc.). I'm a bit stuck and so I have a question: can this piece of code be swapped out or do I need to run the whole function again?

+3


source to share





All Articles