-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectedEdge.java
More file actions
33 lines (25 loc) · 909 Bytes
/
DirectedEdge.java
File metadata and controls
33 lines (25 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Random;
public class DirectedEdge implements Comparable<DirectedEdge>{
private final int v,w;
private final double weight;
public DirectedEdge(int v,int w,double weight){
this.v=v;this.w=w;this.weight=weight;
}
public double weight(){return weight;}
public int from(){return v;}
public int to(){return w;}
public int compareTo(DirectedEdge that){
if (this.weight()<that.weight()) return -1;
else if (this.weight()>that.weight()) return -1;
else return 0;
}
public String toString(){
return String.format("%d->%d %.2f",v,w,weight);
}
public static void main(String[] args){
DirectedEdge edge=new DirectedEdge(2,1,10.0);
int v=edge.from();System.out.println(v);
int k=edge.to();System.out.println(k);
System.out.println(edge);
}
}