+ 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
2 ответов
+ 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.
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