类 AdjMatrixEdgeWeightedDigraph


  • public class AdjMatrixEdgeWeightedDigraph
    extends java.lang.Object
    The AdjMatrixEdgeWeightedDigraph class represents a edge-weighted digraph of vertices named 0 through V - 1, where each directed edge is of type DirectedEdge and has a real-valued weight. It supports the following two primary operations: add a directed edge to the digraph and iterate over all of edges incident from a given vertex. It also provides methods for returning the number of vertices V and the number of edges E. Parallel edges are disallowed; self-loops are permitted.

    This implementation uses an adjacency-matrix representation. All operations take constant time (in the worst case) except iterating over the edges incident from a given vertex, which takes time proportional to V.

    For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 方法概要

      修饰符和类型 方法 说明
      void addEdge​(DirectedEdge e)
      Adds the directed edge e to the edge-weighted digraph (if there is not already an edge with the same endpoints).
      java.lang.Iterable<DirectedEdge> adj​(int v)
      Returns the directed edges incident from vertex v.
      int E()
      Returns the number of edges in the edge-weighted digraph.
      static void main​(java.lang.String[] args)
      Unit tests the AdjMatrixEdgeWeightedDigraph data type.
      java.lang.String toString()
      Returns a string representation of the edge-weighted digraph.
      int V()
      Returns the number of vertices in the edge-weighted digraph.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 构造器详细资料

      • AdjMatrixEdgeWeightedDigraph

        public AdjMatrixEdgeWeightedDigraph​(int V)
        Initializes an empty edge-weighted digraph with V vertices and 0 edges.
        参数:
        V - the number of vertices
        抛出:
        java.lang.IllegalArgumentException - if V < 0
      • AdjMatrixEdgeWeightedDigraph

        public AdjMatrixEdgeWeightedDigraph​(int V,
                                            int E)
        Initializes a random edge-weighted digraph with V vertices and E edges.
        参数:
        V - the number of vertices
        E - the number of edges
        抛出:
        java.lang.IllegalArgumentException - if V < 0
        java.lang.IllegalArgumentException - if E < 0
    • 方法详细资料

      • V

        public int V()
        Returns the number of vertices in the edge-weighted digraph.
        返回:
        the number of vertices in the edge-weighted digraph
      • E

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

        public void addEdge​(DirectedEdge e)
        Adds the directed edge e to the edge-weighted digraph (if there is not already an edge with the same endpoints).
        参数:
        e - the edge
      • adj

        public java.lang.Iterable<DirectedEdge> adj​(int v)
        Returns the directed edges incident from vertex v.
        参数:
        v - the vertex
        返回:
        the directed edges incident from vertex v as an Iterable
        抛出:
        java.lang.IllegalArgumentException - unless 0 <= v < V
      • toString

        public java.lang.String toString()
        Returns a string representation of the edge-weighted digraph. This method takes time proportional to V2.
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        the number of vertices V, followed by the number of edges E, followed by the V adjacency lists of edges
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the AdjMatrixEdgeWeightedDigraph data type.
        参数:
        args - the command-line arguments