Implementato Binary Tree. Bisogbna testarlo. da implementare il tostring
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user