I have been trying how to write a TreeList but failed so I googled one up and learn't from there. That works but what I am now trying to do and what I cannot find is how to split a TreeList. I have created 2 examples and both have failed me. The program just crashes. I am using Java and the TreeList class I am basing of is http://yet-another-tree-structure.googlecode.com/svn/trunk/java/src/com/tree/.
Original one
public TreeNode<T> removeAndCreate() {
TreeNode<T> tn = new TreeNode<T>(data);
tn.children = children;
tn.elementsIndex = elementsIndex;
elementsIndex.remove(this);
children.remove(this);
return tn;
}
The newer one I am using
public TreeNode<T> split() {
TreeNode<T> tP = parent;
while (tP.isRoot() == false) {
tP = tP.parent;
}
TreeNode<T> tn = new TreeNode<T>(data);
tn.children = children;
tn.elementsIndex = elementsIndex;
tP.elementsIndex.remove(this);
tP.children.remove(this);
return tn;
}
I thank you for the help I receive in advance.