Skip to content

Commit 4afc77f

Browse files
committed
.
1 parent 967653d commit 4afc77f

File tree

13 files changed

+199
-335
lines changed

13 files changed

+199
-335
lines changed
File renamed without changes.
File renamed without changes.

Graphs/Edge.java

-65
This file was deleted.

Graphs/EdgeWeightedDiGraph.java

-93
This file was deleted.

Graphs/EdgeWeightedGraph.java

-95
This file was deleted.
File renamed without changes.

Graphs/ShortestPath/Graph.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// A simple undirected graph data structure API.
2+
3+
import java.util.*;
4+
5+
public class Graph {
6+
7+
private final int V;
8+
private LinkedList<Integer>[] adj;
9+
private int edges;
10+
11+
public Graph(int V) {
12+
this.V = V;
13+
edges = 0;
14+
adj = (LinkedList<Integer>[]) new LinkedList[V];
15+
for (int i = 0; i < V; i++) {
16+
adj[i] = new LinkedList<Integer>();
17+
}
18+
}
19+
20+
public void addEdge(int v, int w) {
21+
adj[v].add(w);
22+
adj[w].add(v);
23+
edges++;
24+
}
25+
26+
public int V() {
27+
return V;
28+
}
29+
30+
public int E() {
31+
return edges;
32+
}
33+
34+
public String toString() {
35+
String retstr = "";
36+
for (int i = 0; i < V ; i++) {
37+
retstr += i + " -> ";
38+
for (int x : adj(i)) {
39+
retstr += x + " ";
40+
}
41+
retstr += "\n";
42+
}
43+
return retstr;
44+
}
45+
46+
public Iterable<Integer> adj(int v) {
47+
return adj[v];
48+
}
49+
50+
public static void main(String[] args) {
51+
Graph g = new Graph(6);
52+
g.addEdge(1,0);
53+
System.out.println(g.E());
54+
}
55+
}

Graphs/ShortestUPath.java

-62
This file was deleted.

0 commit comments

Comments
 (0)