forked from anku580/Java-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
35 lines (28 loc) · 641 Bytes
/
Graph.java
File metadata and controls
35 lines (28 loc) · 641 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
34
35
import java.util.LinkedList;
public class Graph {
private int V;
private int E;
private LinkedList<Integer>[] adj;
public Graph(int V) {
this.V = V;
this.E = 0;
this.adj = new LinkedList[this.V];
for(int i = 0; i < V; i++) {
this.adj[i] = new LinkedList<>();
}
}
public void addEdge(int s, int d) {
this.adj[s].add(d);
this.adj[d].add(s);
this.E++;
}
public LinkedList<Integer> adj(int v) {
return this.adj[v];
}
public int V() {
return this.V;
}
public int E() {
return this.E;
}
}