Aggiunti alcuni esercizi

This commit is contained in:
2014-06-03 23:12:17 +02:00
parent 01c626d0e0
commit 7f2845fe2d
32 changed files with 1719 additions and 330 deletions

View File

@@ -195,33 +195,6 @@ public class LinkedTree <E> implements Tree<E> {
return null;
}
public int depth ( Position<E> v) throws InvalidPositionException{
TreePosition<E> a = checkPosition(v);
if (a.getParent() == null)
return 0;
return (depth(a.getParent()) + 1);
}
public int height () throws EmptyTreeException{
return height_f(root());
}
public int height_f ( Position<E> v) {
TreePosition<E> a = checkPosition(v);
if (isExternal(a))
return 0;
int max = 0;
for ( Position<E> w : a.getChildren()){
if (max == 0 || height_f(w) > max){
max = height_f(w);
}
}
return 1 + max;
}
@Override
public String toString() {
String to_return = "";