-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.java
36 lines (36 loc) · 937 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
import java.io.*;
import java.util.*;
class solution
{
static class Graph
{
int Vertex;
LinkedList<Integer> adjArray[];
Graph(int Vertex)
{
this.Vertex=Vertex;
adjArray=new LinkedList[Vertex];
for(int i=0;i<Vertex;i++)
{
adjArray[i]=new LinkedList<>();
}
}
}
static void addEdge(Graph graph, int source, int destination)
{
graph.adjArray[source].add(destination);
graph.adjArray[destination].add(source);
}
static void printGraph(Graph graph)
{
for(int v=0;v<graph.Vertex;v++)
{
System.out.println("Adjacency list of vertex "+ v);
System.out.print("head");
for(Integer pCrawl: graph.adjArray[v]){
System.out.print(" -> "+pCrawl);
}
System.out.println("\n");
}
}
}