package net.datastructures; /** * 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; }