Package dsa

Class EdgeWeightedDiGraph


  • public class EdgeWeightedDiGraph
    extends Object
    A data type to represent a directed graph with weighted edges.
    • Constructor Summary

      Constructors 
      Constructor Description
      EdgeWeightedDiGraph​(int V)
      Constructs an empty edge-weighted digraph with V vertices and 0 edges.
      EdgeWeightedDiGraph​(stdlib.In in)
      Constructs an edge-weighted digraph from the input stream in.
    • Constructor Detail

      • EdgeWeightedDiGraph

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

        public EdgeWeightedDiGraph​(stdlib.In in)
        Constructs an edge-weighted digraph 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 digraph.
        Returns:
        the number of vertices in this edge-weighted digraph.
      • E

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

        public void addEdge​(DiEdge e)
        Adds a directed edge e to this edge-weighted digraph.
        Parameters:
        e - the directed edge.
      • adj

        public Iterable<DiEdge> adj​(int v)
        Returns the directed edges incident from vertex v in this edge-weighted digraph.
        Parameters:
        v - the vertex.
        Returns:
        the directed edges incident from vertex v in this edge-weighted digraph.
      • outDegree

        public int outDegree​(int v)
        Returns the out-degree of vertex v in this edge-weighted digraph.
        Parameters:
        v - the vertex.
        Returns:
        the out-degree of vertex v in this edge-weighted digraph.
      • inDegree

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

        public Iterable<DiEdge> edges()
        Returns all the directed edges in this edge-weighted digraph.
        Returns:
        all the directed edges in this edge-weighted digraph.
      • toString

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

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