forked from realpacific/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.java
54 lines (44 loc) · 1.15 KB
/
Graph.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
package graphs.commons;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Graph {
public List<Vertex> vertices;
public Graph() {
vertices = new ArrayList<>();
}
@Override
public String toString() {
return String.format("Graph(%s)", Arrays.toString(vertices.toArray()));
}
/**
* The node in a graph
*/
public static class Vertex {
public String value;
public List<Edge> edges = new ArrayList<>();
public State state = State.UNVISITED;
public Vertex(String value) {
this.value = value;
}
@Override
public String toString() {
return String.format("Vertex(%s)", value);
}
}
/**
* The line between two nodes or vertices in graph
*/
public static class Edge {
public Vertex start;
public Vertex end;
public Edge(Vertex start, Vertex end) {
this.start = start;
this.end = end;
}
@Override
public String toString() {
return String.format("Edge(%s, %s)", start, end);
}
}
}