Package dsa

Class EdgeWeightedGraph


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

      • 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 Detail

      • 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.