com.mhhe.clrs2e
Interface Graph

All Known Implementing Classes:
AdjacencyListGraph, AdjacencyMatrixGraph

public interface Graph

Interface for graphs, both directed and undirected. The implementation depends on whether the adjacency list or adjacency matrix representation is used.


Method Summary
 void addEdge(int u, int v)
          Adds an edge to this graph.
 void addEdge(com.mhhe.clrs2e.Vertex u, com.mhhe.clrs2e.Vertex v)
          Adds an edge to this graph.
 com.mhhe.clrs2e.Vertex addVertex(int index, java.lang.String name)
          Adds a vertex to this graph.
 com.mhhe.clrs2e.Vertex addVertex(java.lang.String name)
          Adds a vertex to this graph.
 com.mhhe.clrs2e.Vertex addVertex(com.mhhe.clrs2e.Vertex v)
          Adds a vertex to this graph, given a Vertex.
 java.util.Iterator edgeIterator(int u)
          Returns an iterator that iterates through the edges incident on a given vertex.
 java.util.Iterator edgeIterator(com.mhhe.clrs2e.Vertex u)
          Returns an iterator that iterates through the edges incident on a given vertex.
 int getCardE()
          Returns the number of edges in this graph.
 int getCardV()
          Returns the number of vertices in this graph.
 com.mhhe.clrs2e.Vertex getVertex(int index)
          Returns the vertex with a given index.
 boolean isDirected()
          Returns true if this graph is directed, false if undirected.
 java.util.Iterator vertexIterator()
          Returns an iterator that iterates though all the vertices in the graph.
 

Method Detail

addVertex

public com.mhhe.clrs2e.Vertex addVertex(java.lang.String name)
Adds a vertex to this graph. Given the vertex's name, a Vertex object is created and added. The next available index is used.

Parameters:
name - The vertex's name.
Returns:
The new Vertex object added.

addVertex

public com.mhhe.clrs2e.Vertex addVertex(int index,
                                        java.lang.String name)
Adds a vertex to this graph. Given the vertex's name and index, a Vertex object is created and added.

Parameters:
index - The vertex's index.
name - The vertex's name.
Returns:
The new Vertex object added.

addVertex

public com.mhhe.clrs2e.Vertex addVertex(com.mhhe.clrs2e.Vertex v)
Adds a vertex to this graph, given a Vertex. If the vertex's index is unknown, use the next available index. Otherwise, use the index in the vertex.

Parameters:
v - The Vertex object to add.
Returns:
v.

getVertex

public com.mhhe.clrs2e.Vertex getVertex(int index)
Returns the vertex with a given index.

Parameters:
index - The index of the vertex.
Returns:
The Vertex with the given index.

addEdge

public void addEdge(com.mhhe.clrs2e.Vertex u,
                    com.mhhe.clrs2e.Vertex v)
Adds an edge to this graph. The edge is specified by a pair of Vertex objects.

Parameters:
u - One vertex.
v - The other vertex.

addEdge

public void addEdge(int u,
                    int v)
Adds an edge to this graph. The edge is specified by a pair of vertex indices.

Parameters:
u - The index of one vertex.
v - The index of the other vertex.

vertexIterator

public java.util.Iterator vertexIterator()
Returns an iterator that iterates though all the vertices in the graph.


edgeIterator

public java.util.Iterator edgeIterator(com.mhhe.clrs2e.Vertex u)
Returns an iterator that iterates through the edges incident on a given vertex. Each incident edge is indicated by the corresponding adjacent vertex.

Parameters:
u - The vertex whose incident edges are returned by the iterator.

edgeIterator

public java.util.Iterator edgeIterator(int u)
Returns an iterator that iterates through the edges incident on a given vertex. Each incident edge is indicated by the corresponding adjacent vertex.

Parameters:
u - The index of the vertex whose incident edges are returned by the iterator.

getCardV

public int getCardV()
Returns the number of vertices in this graph.


getCardE

public int getCardE()
Returns the number of edges in this graph.


isDirected

public boolean isDirected()
Returns true if this graph is directed, false if undirected.