Package dsa

Class Edge

  • All Implemented Interfaces:
    Comparable<Edge>

    class Edge
    extends Object
    implements Comparable<Edge>
    An immutable, comparable data type to represent a weighted edge in an undirected graph.
    • Constructor Detail

      • Edge

        public Edge​(int v,
                    int w,
                    double weight)
        Constructs an edge between vertices v and w of the given weight.
        Parameters:
        v - one vertex.
        w - the other vertex.
        weight - the weight.
    • Method Detail

      • either

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

        public int other​(int v)
        Returns the endpoint of this edge that is different from vertex v.
        Parameters:
        v - one endpoint of this edge
        Returns:
        the endpoint of this edge that is different from vertex v.
      • weight

        public double weight()
        Returns the weight of this edge.
        Returns:
        the weight of this edge.
      • toString

        public String toString()
        Returns a string representation of this edge.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this edge.
      • compareTo

        public int compareTo​(Edge other)
        Returns a comparison of this edge with other by their weights.
        Specified by:
        compareTo in interface Comparable<Edge>
        Parameters:
        other - the other edge.
        Returns:
        a comparison of this edge with other by their weights.
      • main

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