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
scheme tree


source to share


No one has answered this question yet

Check out similar questions:

13
the car and the cdr in the Scheme is driving me crazy
2
Haskell tree display function
1
Using the schema to build a tree and print node bypassing in_order
1
Binary schema tree diagram
1
Schematic - Binary Heap Insertion vs Binary Search Tree
1
Vaguely about binary search trees (schema)
1
Sorting function for trees in a schematic
0
schema, height and pstorder tree.
0
add nodes to a tree in a schematic
-five
Binary tree schema path



All Articles
Loading...
X
Show
Funny
Dev
Pics