previous | index | next

Inserting into a BST from a List

Instead of manually inserting nodes, as in:
     (insert 7
       (insert 5
         (insert 3
           (insert 1
             (insert 6
               (insert 2
                 (insert 4 (make-empty-tree))))))))
we can write a procedure called list->bstree that takes nodes from a list and uses insert to create the same BST:
     (list->bstree '(7 5 3 1 6 2 4))
produces:

Writing list->bstree is Exercise 8.7.


previous | index | next