|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.AdjacencyListGraph | +--com.mhhe.clrs2e.WeightedAdjacencyListGraph
Implementation of a weighted graph, using adjacency lists.
The representation and use are similar to the superclass AdjacencyListGraph
. The primary difference is that the inner
class AdjacencyListGraph.Edge
is subclassed here as WeightedAdjacencyListGraph.WeightedEdge
, and objects of this
subclass include a weight. The inner WeightedAdjacencyListGraph.EdgeIterator
class overrides the AdjacencyListGraph.EdgeIterator
class and implements the WeightedEdgeIterator
interface, so that edge weights can be get
and set during iterations through edges.
Nested Class Summary | |
class |
WeightedAdjacencyListGraph.EdgeIterator
Inner class that overrides AdjacencyListGraph.EdgeIterator to implement
WeightedEdgeIterator . |
protected static class |
WeightedAdjacencyListGraph.WeightedEdge
Inner class for weighted edges in adjacency lists. |
Nested classes inherited from class com.mhhe.clrs2e.AdjacencyListGraph |
AdjacencyListGraph.AdjListInfo, AdjacencyListGraph.VertexIterator |
Field Summary |
Fields inherited from class com.mhhe.clrs2e.AdjacencyListGraph |
adj, directed, e, lastAdded |
Constructor Summary | |
WeightedAdjacencyListGraph(int cardV,
boolean directed)
Creates an empty WeightedAdjacencyListGraph . |
Method Summary | |
void |
addEdge(int u,
int v)
Unsupported, since edges in a weighted graph must have weights. |
void |
addEdge(int u,
int v,
double weight)
Adds a weighted edge to this graph. |
void |
addEdge(com.mhhe.clrs2e.Vertex u,
com.mhhe.clrs2e.Vertex v)
Unsupported, since edges in a weighted graph must have weights. |
void |
addEdge(com.mhhe.clrs2e.Vertex u,
com.mhhe.clrs2e.Vertex v,
double weight)
Adds a weighted edge to this graph. |
java.util.Iterator |
edgeIterator(int u)
Returns an iterator that iterates through the weighted edges incident on a given vertex. |
java.util.Iterator |
edgeIterator(com.mhhe.clrs2e.Vertex u)
Returns an iterator that iterates through the weighted edges incident on a given vertex. |
protected com.mhhe.clrs2e.AdjacencyListGraph |
makeEmptyGraph(int cardV,
boolean directed)
Creates and returns an empty WeightedAdjacencyListGraph with no edges, given
the number of vertices and a boolean indicating whether the
graph is directed. |
java.lang.String |
toString()
Returns the String representation of this
weighted graph. |
com.mhhe.clrs2e.WeightedEdgeIterator |
weightedEdgeIterator(int u)
Returns an iterator, of type WeightedEdgeIterator
(so that the caller does not need to cast the result), that
iterates through the weighted edges incident on a given vertex. |
com.mhhe.clrs2e.WeightedEdgeIterator |
weightedEdgeIterator(com.mhhe.clrs2e.Vertex u)
Returns an iterator, of type WeightedEdgeIterator
(so that the caller does not need to cast the result), that
iterates through the weighted edges incident on a given vertex. |
Methods inherited from class com.mhhe.clrs2e.AdjacencyListGraph |
addVertex, addVertex, addVertex, getCardE, getCardV, getVertex, isDirected, useSameVertices, vertexIterator |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public WeightedAdjacencyListGraph(int cardV, boolean directed)
WeightedAdjacencyListGraph
.
cardV
- How many vertices this graph will have.directed
- Flag indicating whether this graph is directed.Method Detail |
public void addEdge(com.mhhe.clrs2e.Vertex u, com.mhhe.clrs2e.Vertex v)
addEdge
in interface Graph
addEdge
in class AdjacencyListGraph
u
- One vertex.v
- The other vertex.
java.lang.UnsupportedOperationException
- always.public void addEdge(int u, int v)
addEdge
in interface Graph
addEdge
in class AdjacencyListGraph
u
- The index of one vertex.v
- The index of the other vertex.
java.lang.UnsupportedOperationException
- always.public void addEdge(com.mhhe.clrs2e.Vertex u, com.mhhe.clrs2e.Vertex v, double weight)
Vertex
objects.
u
- One vertex.v
- The other vertex.weight
- The weight of the edge.public void addEdge(int u, int v, double weight)
u
- The index of one vertex.v
- The index of the other vertex.weight
- The weight of the edge.public java.util.Iterator edgeIterator(com.mhhe.clrs2e.Vertex u)
edgeIterator
in interface Graph
edgeIterator
in class AdjacencyListGraph
u
- The vertex whose incident edges are returned by the
iterator.public java.util.Iterator edgeIterator(int u)
edgeIterator
in interface Graph
edgeIterator
in class AdjacencyListGraph
u
- The index of the vertex whose incident edges are
returned by the iterator.public com.mhhe.clrs2e.WeightedEdgeIterator weightedEdgeIterator(com.mhhe.clrs2e.Vertex u)
WeightedEdgeIterator
(so that the caller does not need to cast the result), that
iterates through the weighted edges incident on a given vertex.
Each incident edge is indicated by the corresponding adjacent
vertex.
u
- The vertex whose incident edges are returned by the
iterator.public com.mhhe.clrs2e.WeightedEdgeIterator weightedEdgeIterator(int u)
WeightedEdgeIterator
(so that the caller does not need to cast the result), that
iterates through the weighted edges incident on a given vertex.
Each incident edge is indicated by the corresponding adjacent
vertex.
u
- The index of the vertex whose incident edges are
returned by the iterator.protected com.mhhe.clrs2e.AdjacencyListGraph makeEmptyGraph(int cardV, boolean directed)
WeightedAdjacencyListGraph
with no edges, given
the number of vertices and a boolean indicating whether the
graph is directed.
makeEmptyGraph
in class AdjacencyListGraph
cardV
- How many vertices in the new graph.directed
- Flag indicating whether this graph is directed.public java.lang.String toString()
String
representation of this
weighted graph.
toString
in class AdjacencyListGraph
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |