-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
33 lines (29 loc) · 805 Bytes
/
Copy pathGraph.java
File metadata and controls
33 lines (29 loc) · 805 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
// Задача : Construct Graph Class (simple)
// Ссылка : https://www.codewars.com/kata/58867e2e2d2177547500007f/java
import java.util.List;
import java.util.ArrayList;
public class Graph {
int V;
int E = 0;
List<List<Integer>> adj;
public Graph(int v) {
if(v < 0) {
throw new IllegalArgumentException();
} else {
this.V = v;
this.adj = new ArrayList<>(V);
for (int i = 0; i < V; i++) {
adj.add(new ArrayList<>());
}
}
}
public void addEdge(int v, int w) {
if(v < 0 || w < 0 || v > V || w > V) {
throw new IllegalArgumentException();
} else {
E++;
adj.get(v).add(w);
adj.get(w).add(v);
}
}
}