I am attempting to implement an iterator class for my binary search tree. (to be more precise, it is a KD-Tree, but I don't think that will change things much). I want the iterator to follow an in-order traversal of the tree. I have an arrayList which contains the leaf nodes in this "in-order" order, and I would like the iterator to iterate through these leaf nodes in this order. How can I use this arrayList to implement next() method?
I have tried creating an int field called index in the Iterator class. Then my next() method would increment the index by 1 and return arrayList.get(index). However, this didn't seem to work.
Using the arrayList to implement next() isn't necessary, but it seemed like the easiest way. If there is a way to do this with the arrayList, that would be preferred. Is this even possible? If not, any advice whatsoever would be welcome! Thanks
arrayList.iterator()to get an iterator, then.