Implementazione parziale di tree
This commit is contained in:
73
tree/LinkedTree.java
Normal file
73
tree/LinkedTree.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package tree;
|
||||
|
||||
import exceptions.BoundaryViolationException;
|
||||
import exceptions.EmptyTreeException;
|
||||
import exceptions.InvalidPositionException;
|
||||
import position.Position;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 07/04/14
|
||||
* Time: 15:45
|
||||
*/
|
||||
public class LinkedTree <E> implements Tree<E> {
|
||||
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Position<E>> positions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E replace(Position<E> v, E e) throws InvalidPositionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position<E> root() throws EmptyTreeException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position<E> parent(Position<E> v) throws InvalidPositionException, BoundaryViolationException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Position<E>> children(Position<E> v) throws InvalidPositionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInternal(Position<E> v) throws InvalidPositionException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExternal(Position<E> v) throws InvalidPositionException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot(Position<E> v) throws InvalidPositionException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
33
tree/Tree.java
Normal file
33
tree/Tree.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package tree;
|
||||
|
||||
import exceptions.BoundaryViolationException;
|
||||
import exceptions.EmptyTreeException;
|
||||
import exceptions.InvalidPositionException;
|
||||
import position.Position;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 07/04/14
|
||||
* Time: 15:17
|
||||
*/
|
||||
public interface Tree<E> extends Iterable<E> {
|
||||
|
||||
|
||||
public int size();
|
||||
public boolean isEmpty();
|
||||
|
||||
public Iterable<Position<E>> positions ();
|
||||
public E replace (Position<E> v, E e) throws InvalidPositionException;
|
||||
public Position<E> root () throws EmptyTreeException;
|
||||
public Position<E> parent (Position <E> v) throws InvalidPositionException, BoundaryViolationException;
|
||||
public Iterable <Position<E>> children (Position<E> v) throws InvalidPositionException; // anche se e' foglia
|
||||
|
||||
public boolean isInternal (Position<E> v) throws InvalidPositionException;
|
||||
public boolean isExternal (Position<E> v) throws InvalidPositionException;
|
||||
public boolean isRoot (Position <E> v) throws InvalidPositionException;
|
||||
|
||||
|
||||
}
|
||||
55
tree/TreeNode.java
Normal file
55
tree/TreeNode.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package tree;
|
||||
|
||||
import position.Position;
|
||||
import position.PositionList;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 07/04/14
|
||||
* Time: 15:30
|
||||
*/
|
||||
public class TreeNode<E> implements TreePosition<E> {
|
||||
|
||||
private E element = null;
|
||||
private TreePosition<E> parent = null;
|
||||
private PositionList<Position<E>> children= null;
|
||||
|
||||
|
||||
public TreeNode(E in_element, TreePosition<E> in_parent, PositionList<Position<E>> in_children ){
|
||||
element = in_element;
|
||||
parent = in_parent;
|
||||
children = in_children;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setElement(E o) {
|
||||
element = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionList<Position<E>> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildren(PositionList<Position<E>> c) {
|
||||
children = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreePosition<E> getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(TreePosition<E> v) {
|
||||
parent = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E element() {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
20
tree/TreePosition.java
Normal file
20
tree/TreePosition.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package tree;
|
||||
|
||||
import position.Position;
|
||||
import position.PositionList;
|
||||
|
||||
/**
|
||||
* Created with xgiovio.macbookair.
|
||||
* User: xgiovio
|
||||
* Date: 07/04/14
|
||||
* Time: 15:31
|
||||
*/
|
||||
public interface TreePosition<E> extends Position<E> {
|
||||
|
||||
public void setElement(E o);
|
||||
public PositionList<Position<E>> getChildren ();
|
||||
public void setChildren (PositionList<Position<E>> c);
|
||||
public TreePosition<E> getParent();
|
||||
public void setParent (TreePosition<E> v);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user