+ 1

Implement iterable in a generic binary tree

Hi, I'm making a binary tree in java but i don't know how to implement iterable, I've done that with a linked list but here i don't have positions, so is there another way to get the next element? I've thought about a recursive method but that doesn't seem very well to me. This is my code https://code.sololearn.com/c75FAa70ospy/?ref=app

4th Nov 2018, 8:48 PM
Daniel
Daniel - avatar
2 Respuestas
+ 2
I believe your post order code and in order code should be swapped. I'd add a link to parent to the leaf class so you can go back up the tree from any leaf. To iterate, store the next node and a state of left or right indicating which element to process next.
6th Nov 2018, 8:02 PM
John Wells
John Wells - avatar
0
yeah I've just noticed that about post and in order, I've already done the iterable part with an array but I'll try to do it as you say
9th Nov 2018, 2:05 PM
Daniel
Daniel - avatar