Package algs43

Class Edge

java.lang.Object
algs43.Edge
All Implemented Interfaces:
Comparable<Edge>

public class Edge extends Object implements Comparable<Edge>
The Edge class represents a weighted edge in an undirected graph.

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

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
     
    private final int
     
    private final double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Edge(int v, int w, double weight)
    Create an edge between v and w with given weight.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compare edges by weight.
    int
    Return either endpoint of this edge.
    static void
    main(String[] args)
    Test client.
    int
    other(int vertex)
    Return the endpoint of this edge that is different from the given vertex (unless a self-loop).
    Return a string representation of this edge.
    double
    Return the weight of this edge.

    Methods inherited from class java.lang.Object

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

    • v

      private final int v
    • w

      private final int w
    • weight

      private final double weight
  • Constructor Details

    • Edge

      public Edge(int v, int w, double weight)
      Create an edge between v and w with given weight.
  • Method Details

    • weight

      public double weight()
      Return the weight of this edge.
    • either

      public int either()
      Return either endpoint of this edge.
    • other

      public int other(int vertex)
      Return the endpoint of this edge that is different from the given vertex (unless a self-loop).
    • compareTo

      public int compareTo(Edge that)
      Compare edges by weight.
      Specified by:
      compareTo in interface Comparable<Edge>
    • toString

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

      public static void main(String[] args)
      Test client.