This repository was archived by the owner on Aug 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirectedEdge.java
More file actions
63 lines (55 loc) · 1.5 KB
/
Copy pathDirectedEdge.java
File metadata and controls
63 lines (55 loc) · 1.5 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
54
55
56
57
58
59
60
61
62
63
/*************************************************************************
* Compilation: javac DirectedEdge.java
* Execution: java DirectedEdge
*
* Immutable weighted directed edge.
*
*************************************************************************/
/**
* The <tt>DirectedEdge</tt> class represents a weighted edge in an directed graph.
* <p>
* For additional documentation, see <a href="http://algs4.cs.princeton.edu/44sp">Section 4.4</a> of
* <i>Algorithms, 4th Edition</i> by Robert Sedgewick and Kevin Wayne.
*/
public class DirectedEdge {
private final int v;
private final int w;
private final double weight;
/**
* Create a directed edge from v to w with given weight.
*/
public DirectedEdge(int v, int w, double weight) {
this.v = v;
this.w = w;
this.weight = weight;
}
/**
* Return the vertex where this edge begins.
*/
public int from() {
return v;
}
/**
* Return the vertex where this edge ends.
*/
public int to() {
return w;
}
/**
* Return the weight of this edge.
*/
public double weight() { return weight; }
/**
* Return a string representation of this edge.
*/
public String toString() {
return v + "->" + w + " " + String.format("%5.2f", weight);
}
/**
* Test client.
*/
public static void main(String[] args) {
DirectedEdge e = new DirectedEdge(12, 23, 3.14);
StdOut.println(e);
}
}