Advertisement
Guest User

Edge class for Reverse-delete mst

a guest
Mar 15th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package reverse_delete;
  2.  
  3. public class Edge implements Comparable{
  4.     private int startPoint;
  5.     private int endPoint;
  6.     private float weight;
  7.  
  8.     public Edge(int startPoint, int endPoint, float weight) {
  9.         this.startPoint = startPoint;
  10.         this.endPoint = endPoint;
  11.         this.weight = weight;
  12.     }
  13.  
  14.     public int getStartPoint() {
  15.         return startPoint;
  16.     }
  17.  
  18.     public int getEndPoint() {
  19.         return endPoint;
  20.     }
  21.  
  22.     public float getWeight() {
  23.         return weight;
  24.     }
  25.    
  26.     public Edge opposite(){
  27.         Edge e = new Edge(endPoint, startPoint, weight);
  28.         return e;
  29.     }
  30.  
  31.     public boolean equals(Edge other) {
  32.         if (this.startPoint == other.startPoint) {
  33.             if (this.endPoint == other.endPoint) {
  34.                 return true;
  35.             }
  36.         }
  37.         return false;
  38.     }
  39.    
  40.     public int compareTo(Object o) {
  41.         Edge other = (Edge) o;
  42.         // inverse comparison to get decreasing order
  43.         return Double.compare(other.weight, this.weight);
  44.     }
  45.  
  46.     public String toString() {
  47.         return startPoint + "-" + endPoint + " (" + weight + ")";
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement