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 Summary

    Constructors
    Constructor
    Description
    Edge(int v, int w, double weight)
    Constructs an edge between vertices v and w of the given weight.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(Edge other)
    Returns a comparison of this edge with other by their weights.
    int
    Returns one endpoint of this edge.
    static void
    main(String[] args)
    Unit tests the data type.
    int
    other(int v)
    Returns the endpoint of this edge that is different from vertex v.
    Returns a string representation of this edge.
    double
    Returns the weight of this edge.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

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

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