-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.java
More file actions
53 lines (47 loc) · 1.21 KB
/
Copy pathEdge.java
File metadata and controls
53 lines (47 loc) · 1.21 KB
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
/**
@author Ruvimbo Joy Sithole
@author Faustina Awuntayami Ama
* Creates an edge that stores values for the sources and destination to which it is incident
*/
public class Edge {
String source;
String destination;
int weight;
/**
* The constructor
* @param src the source vertex
* @param dst the destination vertex
* @param value the weight of the edge
*/
public Edge(String src, String dst, int value){
source = src;
destination = dst;
weight = value;
}
/**
* gets the vertices associated with the edge
* @return String of the vertices (source, destination)
*/
String getElements(){
// Could this just have been set(this.source, this.destination)
return "(" + this.source + ", " + this.destination + ")";
}
/**
* Retrieves the destination vertex from the given source u
* @param v source vertex
* @return vertex that shares the same edge as u
*/
String opposite(String v){
if (v == source){
return destination;
}
else
return source;
}
/**
* @return the weight of the edge
*/
int distance(){
return weight;
}
}