public class CarlWeightedGraph extends java.lang.Object implements WeightedGraph
Constructor and Description |
---|
CarlWeightedGraph()
Default constructor: an empty directed graph.
|
CarlWeightedGraph(boolean directed)
Constructs an empty graph with the specified directedness, with a
sentinel value of Double.POSITIVE_INFINITY.
|
CarlWeightedGraph(boolean directed,
int N)
Constructs a graph with N vertices and the specified directedness, with a
sentinel value of Double.POSITIVE_INFINITY.
|
CarlWeightedGraph(boolean directed,
int N,
double sentinel)
Constructs a graph with N vertices and the specified directedness and
sentinel value.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addEdge(int begin,
int end,
double weight)
Adds a weighted edge between two vertices.
|
int |
addVertex()
Adds a new vertex.
|
void |
clear()
Removes all vertices and edges from the graph.
|
int |
getDegree(int v)
Returns the out-degree of the specified vertex.
|
int |
getInDegree(int v)
Returns the in-degree of the specified vertex.
|
java.lang.Iterable<java.lang.Integer> |
getNeighbors(int v)
Returns an iterator over the neighbors of the specified vertex.
|
double |
getWeight(int begin,
int end)
Gets the weight of the edge between two vertices.
|
boolean |
hasEdge(int begin,
int end)
Checks whether an edge exists between two vertices.
|
boolean |
isDirected()
Returns true if the graph is directed.
|
boolean |
isEmpty()
Returns true if there are no vertices in the graph.
|
double |
missingEdgeSentinel()
Returns the "sentinel" weight value for edges not in the graph.
|
int |
numEdges()
Returns the number of edges in the graph.
|
int |
numVerts()
Returns the number of vertices in the graph.
|
boolean |
setWeight(int begin,
int end,
double weight)
Sets the weight of an edge already in the graph.
|
public CarlWeightedGraph()
public CarlWeightedGraph(boolean directed)
public CarlWeightedGraph(boolean directed, int N)
public CarlWeightedGraph(boolean directed, int N, double sentinel)
public int addVertex()
public boolean addEdge(int begin, int end, double weight)
addEdge
in interface WeightedGraph
public boolean hasEdge(int begin, int end)
public boolean setWeight(int begin, int end, double weight)
setWeight
in interface WeightedGraph
public double getWeight(int begin, int end)
getWeight
in interface WeightedGraph
public int getDegree(int v)
public int getInDegree(int v)
getInDegree
in interface Graph
public java.lang.Iterable<java.lang.Integer> getNeighbors(int v)
getNeighbors
in interface Graph
public int numVerts()
public int numEdges()
public boolean isDirected()
isDirected
in interface Graph
public boolean isEmpty()
public void clear()
public double missingEdgeSentinel()
missingEdgeSentinel
in interface WeightedGraph