diff --git a/graph/AdjacencyListGraph.java b/graph/AdjacencyListGraph.java index 30f6543..b9352f2 100644 --- a/graph/AdjacencyListGraph.java +++ b/graph/AdjacencyListGraph.java @@ -7,6 +7,12 @@ package graph; * Time: 16:30 */ +import exceptions.InvalidPositionException; +import map.HashTableMap; +import position.NodePositionList; +import position.Position; +import position.PositionList; + import java.util.Iterator; /** @@ -15,7 +21,6 @@ import java.util.Iterator; * @author Roberto Tamassia, Eric Zamore */ - /* public class AdjacencyListGraph implements Graph { protected NodePositionList> VList; // container for vertices @@ -179,8 +184,7 @@ public class AdjacencyListGraph implements Graph { } // Implementation of a decorable position by means of a hash table. - protected static class MyPosition - extends HashTableMap implements DecorablePosition { + protected static class MyPosition extends HashTableMap implements DecorablePosition { // The element stored at this position. protected T elem; // Returns the element stored at this position. @@ -223,8 +227,7 @@ public class AdjacencyListGraph implements Graph { //Implementation of a vertex for an undirected adjacency list //graph. Each vertex stores its incidence container and position //in the vertex container of the graph. - protected class MyVertex - extends MyPosition implements Vertex { + protected class MyVertex extends MyPosition implements Vertex { // Incidence container of the vertex. protected PositionList> incEdges; // Position of the vertex in the vertex container of the graph. @@ -317,6 +320,4 @@ public class AdjacencyListGraph implements Graph { "," + endVertices[1].toString() + ")"; } } -} - -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/graph/DecorablePosition.java b/graph/DecorablePosition.java new file mode 100644 index 0000000..50d4080 --- /dev/null +++ b/graph/DecorablePosition.java @@ -0,0 +1,15 @@ +package graph; + +import map.Map; +import position.Position; + +/** + * An interface for a position that can be marked with an arbitrary + * number of decorations. + * + * @author Roberto Tamassia, Michael Goodrich + */ + +public interface DecorablePosition extends Position, Map {} + // no new methods needed -- this is a mixture of Position and Map. + diff --git a/graph/DirectedGraph.java b/graph/DirectedGraph.java new file mode 100644 index 0000000..a897db4 --- /dev/null +++ b/graph/DirectedGraph.java @@ -0,0 +1,12 @@ +package graph; + +/** + * Created with MONSTER. + * User: xgiovio + * Date: 20/05/2014 + * Time: 19:59 + */ +public interface DirectedGraph extends Graph{ + public boolean isDirected(Edge e); + public Edge insertDirectedEdge(Vertex u, Vertex v, V o); +} diff --git a/graph/Edge.java b/graph/Edge.java new file mode 100644 index 0000000..eccc6ba --- /dev/null +++ b/graph/Edge.java @@ -0,0 +1,6 @@ +package graph; +/** + * An interface for an edge of a graph. + * @author Roberto Tamassia + */ +public interface Edge extends DecorablePosition { } diff --git a/graph/Graph.java b/graph/Graph.java new file mode 100644 index 0000000..2dcde31 --- /dev/null +++ b/graph/Graph.java @@ -0,0 +1,55 @@ +package graph; + +import exceptions.InvalidPositionException; + +/** + * An interface for a graph. + * @author Roberto Tamassia + */ + +public interface Graph { + + /** Returns the number of vertices of the graph */ + public int numVertices(); + + /** Returns the number of edges of the graph */ + public int numEdges(); + + /** Returns the vertices of the graph as an iterable collection */ + public Iterable> vertices(); + + /** Returns the edges of the graph as an iterable collection */ + public Iterable> edges(); + + /** Replaces the element of a given vertex with a new element and returns the old element */ + public V replace(Vertex p, V o) throws InvalidPositionException; + + /** Replaces the element of a given edge with a new element and returns the old element */ + public E replace(Edge p, E o) throws InvalidPositionException; + + /** Returns the edges incident on a vertex as an iterable collection */ + public Iterable> incidentEdges(Vertex v) throws InvalidPositionException; + + /** Returns the endvertices of a vertex as an array of length 2 */ + public Vertex[] endVertices(Edge e) throws InvalidPositionException; + + /** Returns the other endvertex of an incident edge */ + public Vertex opposite(Vertex v, Edge e) throws InvalidPositionException; + + /** Tests whether two vertices are adjacent */ + public boolean areAdjacent(Vertex u, Vertex v) throws InvalidPositionException; + + /** Inserts and return a new vertex with a given element */ + public Vertex insertVertex(V o); + + /** Inserts and return a new edge with a given element between two vertices */ + public Edge insertEdge(Vertex u, Vertex v, E o) throws InvalidPositionException; + + /** Removes a vertex and all its incident edges and returns the element stored at the removed vertex */ + public V removeVertex(Vertex v) throws InvalidPositionException; + + /** Removes an edge and return its element */ + public E removeEdge(Edge e) throws InvalidPositionException; +} + + diff --git a/graph/Vertex.java b/graph/Vertex.java new file mode 100644 index 0000000..d3ef3d4 --- /dev/null +++ b/graph/Vertex.java @@ -0,0 +1,6 @@ +package graph; +/** + * An interface for a vertex of a graph. + * @author Roberto Tamassia + */ +public interface Vertex extends DecorablePosition { }