| 限定符和类型 | 字段和说明 |
|---|---|
protected List<Edge<T>> |
edges
Vector
|
protected Vertex<T> |
rootVertex
The vertex identified as the root of the graph
|
protected Map<String,Vertex<T>> |
vertices
Map
|
static int |
VISIT_COLOR_BLACK
Color used to mark nodes after descendants are completely visited
|
static int |
VISIT_COLOR_GREY
Color used to mark nodes as they are first visited in DFS order
|
static int |
VISIT_COLOR_WHITE
Color used to mark unvisited nodes
|
| 构造器和说明 |
|---|
Graph()
Construct a new graph without any vertices or edges
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
addBiEdge(Vertex<T> from,
Vertex<T> to,
int weight)
Insert a bidirectional (两个方向的) Edge
|
boolean |
addEdge(String from,
String to) |
boolean |
addEdge(String from,
String to,
int weight) |
boolean |
addEdge(String from,
String to,
String label,
int weight) |
boolean |
addEdge(Vertex<T> from,
Vertex<T> to) |
boolean |
addEdge(Vertex<T> from,
Vertex<T> to,
int weight) |
boolean |
addEdge(Vertex<T> from,
Vertex<T> to,
String label,
int weight)
Insert a directed, weighted Edge
|
boolean |
addVertex(String name,
T data) |
boolean |
addVertex(Vertex<T> v)
Add a vertex to the graph
|
Vertex<T> |
findVertexByData(T data,
Comparator<T> compare)
Search the verticies for one with data.
|
List<Edge<T>> |
getEdges()
Get the graph edges
|
Vertex<T> |
getRootVertex()
Get the root vertex
|
Vertex<T> |
getVertex(int n)
Get the given Vertex.
|
Vertex<T> |
getVertex(String name)
Search the verticies for one with name.
|
List<String> |
getVertexNames() |
List<Vertex<T>> |
getVertices()
Get the graph vertices
|
boolean |
hasBiEdge(String from,
String to) |
boolean |
hasEdge(String from,
String to) |
boolean |
hasVertex(String name) |
boolean |
isEmpty()
Are there any verticies in the graph
|
boolean |
removeEdge(String from,
String to) |
boolean |
removeEdge(Vertex<T> from,
Vertex<T> to)
Remove an Edge
|
boolean |
removeVertex(String name) |
boolean |
removeVertex(String vertexName,
boolean removeUnsharedOutgoing) |
boolean |
removeVertex(Vertex<T> v)
Remove a vertex from the graph
|
boolean |
removeVertex(Vertex<T> v,
boolean removeUnsharedOutgoing) |
void |
setRootVertex(Vertex<T> vertex)
Set a vertex vertex.
|
int |
size()
Get the vertex count.
|
String |
toString() |
public static final int VISIT_COLOR_WHITE
public static final int VISIT_COLOR_GREY
public static final int VISIT_COLOR_BLACK
public boolean isEmpty()
public int size()
public Vertex<T> getRootVertex()
public void setRootVertex(Vertex<T> vertex)
vertex - - the vertex to set as the vertex and optionally add if it
does not exist in the graph.public boolean addVertex(Vertex<T> v)
v - the Vertex to addpublic boolean removeVertex(String name)
public boolean removeVertex(Vertex<T> v)
v - the Vertex to removepublic boolean removeVertex(String vertexName, boolean removeUnsharedOutgoing)
public Vertex<T> getVertex(int n)
n - the index [0, size()-1] of the Vertex to accesspublic Vertex<T> getVertex(String name)
name - - the vertex namepublic boolean hasVertex(String name)
public Vertex<T> findVertexByData(T data, Comparator<T> compare)
data - - the vertex data to matchcompare - - the comparator to perform the matchpublic boolean addEdge(String from, String to) throws IllegalArgumentException
public boolean addEdge(String from, String to, int weight) throws IllegalArgumentException
public boolean addEdge(String from, String to, String label, int weight) throws IllegalArgumentException
public boolean addEdge(Vertex<T> from, Vertex<T> to, String label, int weight)
from - - the Edgeto - - the Edgeweight - - the Edgepublic boolean addBiEdge(Vertex<T> from, Vertex<T> to, int weight)
from - - the Edgeto - - the Edgeweight - - the EdgeIllegalArgumentException - if from/to are not verticies in
the graphpublic boolean removeEdge(Vertex<T> from, Vertex<T> to)
from - - the Edgeto - - the EdgeCopyright © 2022. All rights reserved.