Aggiunto graph
This commit is contained in:
@@ -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<V,E> implements Graph<V,E> {
|
||||
|
||||
protected NodePositionList<Vertex<V>> VList; // container for vertices
|
||||
@@ -179,8 +184,7 @@ public class AdjacencyListGraph<V,E> implements Graph<V,E> {
|
||||
}
|
||||
|
||||
// Implementation of a decorable position by means of a hash table.
|
||||
protected static class MyPosition<T>
|
||||
extends HashTableMap<Object,Object> implements DecorablePosition<T> {
|
||||
protected static class MyPosition<T> extends HashTableMap<Object,Object> implements DecorablePosition<T> {
|
||||
// The element stored at this position.
|
||||
protected T elem;
|
||||
// Returns the element stored at this position.
|
||||
@@ -223,8 +227,7 @@ public class AdjacencyListGraph<V,E> implements Graph<V,E> {
|
||||
//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<V>
|
||||
extends MyPosition<V> implements Vertex<V> {
|
||||
protected class MyVertex<V> extends MyPosition<V> implements Vertex<V> {
|
||||
// Incidence container of the vertex.
|
||||
protected PositionList<Edge<E>> incEdges;
|
||||
// Position of the vertex in the vertex container of the graph.
|
||||
@@ -318,5 +321,3 @@ public class AdjacencyListGraph<V,E> implements Graph<V,E> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
15
graph/DecorablePosition.java
Normal file
15
graph/DecorablePosition.java
Normal file
@@ -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<E> extends Position<E>, Map<Object,Object> {}
|
||||
// no new methods needed -- this is a mixture of Position and Map.
|
||||
|
||||
12
graph/DirectedGraph.java
Normal file
12
graph/DirectedGraph.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package graph;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 20/05/2014
|
||||
* Time: 19:59
|
||||
*/
|
||||
public interface DirectedGraph<V, E> extends Graph<V,E>{
|
||||
public boolean isDirected(Edge<E> e);
|
||||
public Edge<E> insertDirectedEdge(Vertex<V> u, Vertex<V> v, V o);
|
||||
}
|
||||
6
graph/Edge.java
Normal file
6
graph/Edge.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package graph;
|
||||
/**
|
||||
* An interface for an edge of a graph.
|
||||
* @author Roberto Tamassia
|
||||
*/
|
||||
public interface Edge<E> extends DecorablePosition<E> { }
|
||||
55
graph/Graph.java
Normal file
55
graph/Graph.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package graph;
|
||||
|
||||
import exceptions.InvalidPositionException;
|
||||
|
||||
/**
|
||||
* An interface for a graph.
|
||||
* @author Roberto Tamassia
|
||||
*/
|
||||
|
||||
public interface Graph<V, E> {
|
||||
|
||||
/** 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<Vertex<V>> vertices();
|
||||
|
||||
/** Returns the edges of the graph as an iterable collection */
|
||||
public Iterable<Edge<E>> edges();
|
||||
|
||||
/** Replaces the element of a given vertex with a new element and returns the old element */
|
||||
public V replace(Vertex<V> 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<E> p, E o) throws InvalidPositionException;
|
||||
|
||||
/** Returns the edges incident on a vertex as an iterable collection */
|
||||
public Iterable<Edge<E>> incidentEdges(Vertex<V> v) throws InvalidPositionException;
|
||||
|
||||
/** Returns the endvertices of a vertex as an array of length 2 */
|
||||
public Vertex[] endVertices(Edge<E> e) throws InvalidPositionException;
|
||||
|
||||
/** Returns the other endvertex of an incident edge */
|
||||
public Vertex<V> opposite(Vertex<V> v, Edge<E> e) throws InvalidPositionException;
|
||||
|
||||
/** Tests whether two vertices are adjacent */
|
||||
public boolean areAdjacent(Vertex<V> u, Vertex<V> v) throws InvalidPositionException;
|
||||
|
||||
/** Inserts and return a new vertex with a given element */
|
||||
public Vertex<V> insertVertex(V o);
|
||||
|
||||
/** Inserts and return a new edge with a given element between two vertices */
|
||||
public Edge<E> insertEdge(Vertex<V> u, Vertex<V> 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> v) throws InvalidPositionException;
|
||||
|
||||
/** Removes an edge and return its element */
|
||||
public E removeEdge(Edge<E> e) throws InvalidPositionException;
|
||||
}
|
||||
|
||||
|
||||
6
graph/Vertex.java
Normal file
6
graph/Vertex.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package graph;
|
||||
/**
|
||||
* An interface for a vertex of a graph.
|
||||
* @author Roberto Tamassia
|
||||
*/
|
||||
public interface Vertex<E> extends DecorablePosition<E> { }
|
||||
Reference in New Issue
Block a user