-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.java
55 lines (44 loc) · 862 Bytes
/
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
55
package linkstaterouting;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Graph
{
List<LinkedList<LinkStateRouterInfo>> adjacencyList;
public Graph(int size)
{
adjacencyList = new ArrayList<>(size);
for (int i = 0; i < size; i++)
{
adjacencyList.add(null);
}
}
public void insertAt(int id, LinkedList<LinkStateRouterInfo> directlyConnectedNodes)
{
adjacencyList.set(id, directlyConnectedNodes);
}
public LinkedList<LinkStateRouterInfo> getInfoByID(int id)
{
return adjacencyList.get(id);
}
public boolean contains(int id)
{
if(adjacencyList.get(id) == null)
{
return false;
}
return true;
}
public int size()
{
int size = 0;
for (int i = 0; i < adjacencyList.size(); i++)
{
if (adjacencyList.get(i) != null)
{
size++;
}
}
return size;
}
}