类 Edge

  • 所有已实现的接口:
    java.lang.Comparable<Edge>

    public class Edge
    extends java.lang.Object
    implements java.lang.Comparable<Edge>
    The Edge class represents a weighted edge in an EdgeWeightedGraph. Each edge consists of two integers (naming the two vertices) and a real-value weight. The data type provides methods for accessing the two endpoints of the edge and the weight. The natural order for this data type is by ascending order of weight.

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

    • 构造器概要

      构造器 
      构造器 说明
      Edge​(int v, int w, double weight)
      Initializes an edge between vertices v and w of the given weight.
    • 方法概要

      修饰符和类型 方法 说明
      int compareTo​(Edge that)
      Compares two edges by weight.
      int either()
      Returns either endpoint of this edge.
      static void main​(java.lang.String[] args)
      Unit tests the Edge data type.
      int other​(int vertex)
      Returns the endpoint of this edge that is different from the given vertex.
      java.lang.String toString()
      Returns a string representation of this edge.
      double weight()
      Returns the weight of this edge.
      • 从类继承的方法 java.lang.Object

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

      • Edge

        public Edge​(int v,
                    int w,
                    double weight)
        Initializes an edge between vertices v and w of the given weight.
        参数:
        v - one vertex
        w - the other vertex
        weight - the weight of this edge
        抛出:
        java.lang.IllegalArgumentException - if either v or w is a negative integer
        java.lang.IllegalArgumentException - if weight is NaN
    • 方法详细资料

      • weight

        public double weight()
        Returns the weight of this edge.
        返回:
        the weight of this edge
      • either

        public int either()
        Returns either endpoint of this edge.
        返回:
        either endpoint of this edge
      • other

        public int other​(int vertex)
        Returns the endpoint of this edge that is different from the given vertex.
        参数:
        vertex - one endpoint of this edge
        返回:
        the other endpoint of this edge
        抛出:
        java.lang.IllegalArgumentException - if the vertex is not one of the endpoints of this edge
      • compareTo

        public int compareTo​(Edge that)
        Compares two edges by weight. Note that compareTo() is not consistent with equals(), which uses the reference equality implementation inherited from Object.
        指定者:
        compareTo 在接口中 java.lang.Comparable<Edge>
        参数:
        that - the other edge
        返回:
        a negative integer, zero, or positive integer depending on whether the weight of this is less than, equal to, or greater than the argument edge
      • toString

        public java.lang.String toString()
        Returns a string representation of this edge.
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        a string representation of this edge
      • main

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