Package dsa

Class EdgeWeightedGraph

java.lang.Object
dsa.EdgeWeightedGraph

public class EdgeWeightedGraph extends Object
A data type to represent an undirected graph with weighted edges.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty edge-weighted graph with V vertices and 0 edges.
    EdgeWeightedGraph(stdlib.In in)
    Constructs an edge-weighted graph from the input stream in.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds an edge e to this edge-weighted graph.
    adj(int v)
    Returns the edges incident on vertex v in this edge-weighted graph.
    int
    degree(int v)
    Returns the degree of vertex v in this edge-weighted graph.
    int
    E()
    Returns the number of edges in this edge-weighted graph.
    Returns all the edges in this edge-weighted graph.
    static void
    main(String[] args)
    Unit tests the data type.
    Returns a string representation of this edge-weighted graph.
    int
    V()
    Returns the number of vertices in this edge-weighted graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • EdgeWeightedGraph

      public EdgeWeightedGraph(int V)
      Constructs an empty edge-weighted graph with V vertices and 0 edges.
      Parameters:
      V - number of vertices.
    • EdgeWeightedGraph

      public EdgeWeightedGraph(stdlib.In in)
      Constructs an edge-weighted graph from the input stream in.
      Parameters:
      in - the input stream.
  • Method Details

    • V

      public int V()
      Returns the number of vertices in this edge-weighted graph.
      Returns:
      the number of vertices in this edge-weighted graph.
    • E

      public int E()
      Returns the number of edges in this edge-weighted graph.
      Returns:
      the number of edges in this edge-weighted graph.
    • addEdge

      public void addEdge(Edge e)
      Adds an edge e to this edge-weighted graph.
      Parameters:
      e - the edge.
    • adj

      public Iterable<Edge> adj(int v)
      Returns the edges incident on vertex v in this edge-weighted graph.
      Parameters:
      v - the vertex.
      Returns:
      the edges incident on vertex v in this edge-weighted graph.
    • degree

      public int degree(int v)
      Returns the degree of vertex v in this edge-weighted graph.
      Parameters:
      v - the vertex.
      Returns:
      the degree of vertex v in this edge-weighted graph.
    • edges

      public Iterable<Edge> edges()
      Returns all the edges in this edge-weighted graph.
      Returns:
      all the edges in this edge-weighted graph.
    • toString

      public String toString()
      Returns a string representation of this edge-weighted graph.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this edge-weighted graph.
    • main

      public static void main(String[] args)
      Unit tests the data type.
      Parameters:
      args - the command-line arguments.