-
Notifications
You must be signed in to change notification settings - Fork 0
/
KruskalEdge.java
57 lines (50 loc) · 1.22 KB
/
KruskalEdge.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public class KruskalEdge implements Comparable{
private Object firstVertex;
private Object secondVertex;
private int weight;
/**
* KruskalEdge() constructs a KruskalEdge object
@param first is the origin vertex of the edge
@param second is the destination vertex of the edge
@param edgeWeight is the weight of the edge
**/
public KruskalEdge(Object first, Object second, int edgeWeight){
firstVertex = first;
secondVertex = second;
weight = edgeWeight;
}
/**
firstVertex() returns the origin vertex of the KruskalEdge object
**/
public Object firstVertex(){
return firstVertex;
}
/**
secondVertex() returns the destination vertex of the KruskalEdge object
**/
public Object secondVertex(){
return secondVertex;
}
/**
weight() returns the weight of the edge
**/
public int weight(){
return weight;
}
/**
compareTo() implements the Comparable interace
**/
public int compareTo(Object o){
if(o instanceof KruskalEdge){
if(weight < ((KruskalEdge) o).weight()){
return -1;
} else if(weight == ((KruskalEdge) o).weight()){
return 0;
} else{
return 1;
}
} else{
return 0;
}
}
}