Package com.javaholics
Class Graph
java.lang.Object
com.javaholics.Graph
Represents a graph data structure.
This class uses an adjacency list representation of a graph, where each
vertex maintains a list of its adjacent vertices.
The graph is undirected, meaning that an edge between two vertices goes both
ways.
- Author:
- Lindsay Kislingbury, Lea Wiranatha
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
Graph
public Graph()Constructs a new, empty graph.
-
-
Method Details
-
addVertex
Adds a vertex to the graph with the given label. If a vertex with the given label already exists in the graph, this method does nothing.- Parameters:
label
- The label of the vertex to add.
-
addEdge
Adds a vertex with the given label to the graph. If a vertex with the given label already exists in the graph, this method does nothing.- Parameters:
label1
- The label of the first vertex.label2
- The label of the second vertex.
-
getVertex
Returns the vertex with the given label.- Parameters:
label
- The label of the vertex to return.- Returns:
- The vertex with the given label, or null if no such vertex exists.
-