Aggiunti alcuni esercizi
This commit is contained in:
@@ -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 = "";
|
||||
|
||||
Reference in New Issue
Block a user