Don't worry about it, post your solution.
Well, thank you for your answer. After I wrote my previous message, I found that my iterator was not working properly (it worked on my initial test tree, but not on a more complicated tree). I thought I was going to have trouble using a closure, because I don't do that very often, but that turned out to be easy, my problem was to traverse properly the tree without doing stupid mistakes: in some cases I did not get all the leaves, in others I got some duplicate leaves. I *think* that I have it right now. I posted my solution below.