Class Graph

java.lang.Object
com.javaholics.Graph

public class Graph extends Object
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 Details

    • Graph

      public Graph()
      Constructs a new, empty graph.
  • Method Details

    • addVertex

      public void addVertex(String label)
      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

      public void addEdge(String label1, String label2)
      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

      public Vertex getVertex(String label)
      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.