I have a tree, constructed of TreeItems. Each TreeItem has these methods:
TreeItem TreeItem::getParent()
TreeItem[] TreeItem::getChildren()
int TreeItem::indexOf(TreeItem childItem)
I also have an unordered set of TreeItems from this tree. I want to quickly find the first element and the last element of this set.
Any clever ideas?
Select one of a tree items in your set (I'll assume given set is subtree), then first find the parent of this set:
Now you have parent, and you just need iterate its children recursively: