-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgo_transpose.java
More file actions
50 lines (44 loc) · 1.07 KB
/
algo_transpose.java
File metadata and controls
50 lines (44 loc) · 1.07 KB
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
import java.util.*;
class algo_transpose
{
private int V;
private LinkedList<Integer> adj[];
public static ArrayList arr=new ArrayList();
algo_transpose(int V)
{
this.V=V;
adj = new LinkedList[V];
for (int i=0; i<V; ++i)
adj[i] = new LinkedList();
}
void addEdge(int u, int v)
{
adj[u].add(v);
adj[v].add(u);
}
void transpose()
{
algo_transpose gr = new algo_transpose(V);
for(int v=0;v<V;v++)
{
Iterator<Integer> i=adj[v].listIterator();
while(i.hasNext())
{
gr.adj[i.next()].add(v);
}
}
for(int i=0;i<=V;i++)
{
System.out.println(i+"->"+gr.adj[i]);
}
}
public static void main(String args[])
{
algo_transpose g = new algo_transpose(4);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 3);
g.transpose();
}
}