Implementato Binary Tree. Bisogbna testarlo. da implementare il tostring

This commit is contained in:
2014-04-26 22:02:12 +02:00
parent 3fe3c635d8
commit cd1a246d4f
6 changed files with 413 additions and 3 deletions

View File

@@ -173,6 +173,31 @@ public class LinkedTree <E> implements Tree<E> {
}
public E remove (Position<E> v) {
TreePosition<E> a = checkPosition(v);
if (isInternal(a))
throw new InvalidPositionException();
if (size() == 1)
return removeRoot();
PositionList<Position<E>> list = a.getParent().getChildren();
Iterable<Position<Position<E>>> it = list.positions();
for (Position<Position<E>> w : it){
if (w.element() == v){
size--;
return (list.remove(w)).element();
}
}
return null;
}
public int depth ( Position<E> v) throws InvalidPositionException{
TreePosition<E> a = checkPosition(v);
if (a.getParent() == null)