Skip to content

Commit c895ec3

Browse files
Add files via upload
Good Morning
1 parent d12e6e1 commit c895ec3

6 files changed

+109
-0
lines changed

Adjacency_List$Edge.class

367 Bytes
Binary file not shown.

Adjacency_List.class

1.59 KB
Binary file not shown.

Adjacency_List.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.util.ArrayList;
2+
3+
public class Adjacency_List {
4+
//Edge class
5+
static class Edge {
6+
int src; //Source
7+
int dest; //Destigination
8+
9+
//Constructor
10+
public Edge(int s, int d){
11+
this.src = s;
12+
this.dest = d;
13+
}
14+
}
15+
16+
//Create--Graph
17+
18+
public static void createGraph(ArrayList<Edge> graph[]){
19+
for (int i = 0; i < graph.length; i++) {
20+
graph[i] = new ArrayList<Edge>();
21+
// create empty array
22+
// Then Assign the value;
23+
}
24+
graph[0].add(new Edge(0,2));
25+
26+
graph[1].add(new Edge(1,2));
27+
graph[1].add(new Edge(1,3));
28+
29+
graph[2].add(new Edge(2,0));
30+
graph[2].add(new Edge(2,1));
31+
graph[2].add(new Edge(2,3));
32+
33+
graph[3].add(new Edge(3,1));
34+
graph[3].add(new Edge(3,2));
35+
36+
}
37+
public static void main(String[] args) {
38+
//System.out.println("Hi. Nagaraj Loni Good morning");
39+
40+
int V = 4;
41+
42+
ArrayList<Edge> graph[] = new ArrayList[V];
43+
createGraph(graph);
44+
System.out.print("Adj_of_List is----->");
45+
//graph---> Array name, V---> Size
46+
47+
48+
// Print 2;s neighbours
49+
for (int i = 0; i < graph[2].size(); i++) {
50+
Edge e = graph[2].get(i);
51+
System.out.print(+e.dest+ " ");
52+
}
53+
54+
}
55+
}// OUTPUT: Adj_of_List is----->0 1 3

Weight_Adj_List$Edge.class

403 Bytes
Binary file not shown.

Weight_Adj_List.class

1.59 KB
Binary file not shown.

Weight_Adj_List.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.util.ArrayList;
2+
3+
public class Weight_Adj_List {
4+
//Edge class
5+
static class Edge {
6+
int src;
7+
int dest;
8+
int wt;
9+
10+
public Edge(int s, int d, int w){
11+
this.src = s;
12+
this.dest = d;
13+
this.wt = w;
14+
}
15+
}
16+
17+
public static void createGraph(ArrayList<Edge> graph[]){
18+
for (int i = 0; i < graph.length; i++) {
19+
graph[i] = new ArrayList<Edge>();
20+
21+
}
22+
graph[0].add(new Edge(0,2,2));
23+
24+
graph[1].add(new Edge(1,2,10));
25+
graph[1].add(new Edge(1,3,10));
26+
27+
graph[2].add(new Edge(2,0,2));
28+
graph[2].add(new Edge(2,1,10));
29+
graph[2].add(new Edge(2,3,-1));
30+
31+
graph[3].add(new Edge(3,1,0));
32+
graph[3].add(new Edge(3,2,-1));
33+
34+
}
35+
public static void main(String[] args) {
36+
37+
int V = 4;
38+
39+
ArrayList<Edge> graph[] = new ArrayList[V];
40+
createGraph(graph);
41+
42+
for (int i = 0; i < graph[2].size(); i++) {
43+
Edge e = graph[2].get(i);
44+
System.out.println(+e.dest+ " "+e.wt);
45+
}
46+
}
47+
}
48+
/*
49+
2's neibers
50+
51+
0 2
52+
1 10
53+
3 -1
54+
*/

0 commit comments

Comments
 (0)