[plt-scheme] Excersise 14.2.3 - HtDP - Ordered list of binary tree nodes

From: Charlie Turner (charlie.h.turner at googlemail.com)
Date: Fri Feb 20 18:14:22 EST 2009

> How were you able to write down examples if you don't understand what the question is asking of
> you?

That was a silly comment on my behalf. Sorry.

Thank you also for your advice on making the templates for recursion.
I had forgotten about the arrows and when I looked back over that
section, putting the recursions in my template was a breeze.

Marco. Even after writing down what should happen with the (node-ssn
BT), (inorder (node-left BT)) and (inorder (node-right BT)) I still
couldn't see the solution. Your explantion did become crystal clear
for me when I finished the definition though, I'm just slow. Thank you
very much for your time. After re-reading your comments, I feel I have
learned a lot about how I should think when faced with such problems!
(No discredit to the book of course, I should have picked up such
habbits earlier)

And Matthias. Thank you for your suggestion to use such a table. It
was this that finally allowed me to see the solution. I learned that
instead of trying to hold all the details in my head (which clearly
doesn't work) I should write down what is happening every time I call
my definition on new data.

I must say I wasn't using the Deisng Recipies quite has rigourosly as
I should have. Up until now I've been lazy with the excersises. I
think this is because there weren't as many parts to think about as
there are now, with the binary trees, and I've been allowed to get
sloppy. The recursion in the earlier parts fitted easily in my head,
so I was not thinking about the creation of the definition, rather
just the solution -- like Matthias pointed at earlier. I'm pleased
I've learned these lessons the hard way before I continue my journey.

I've really appriciated your patience and time.

(define (inorder BT)
   [(false? BT) empty]
   [else (append (inorder (node-left BT)) (cons (node-ssn BT)
                                                (inorder (node-right BT))))]))

All the best


Posted on the users mailing list.