Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e13afb9

Browse files
committed
n
1 parent 1c9cfe8 commit e13afb9

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package DataAndAlgoL.Chpt9GraphAlgorithms;
2+
3+
import java.util.ArrayList;
4+
import DataAndAlgoL.Chp3LinkedLists.ListNode;
5+
//import DataAndAlgoL.Chp3LinkedLists.LinkedList;
6+
7+
public class GraphAdjList {
8+
ArrayList<Integer> vertices;
9+
ListNode[] edges;
10+
int vertexCount=0;
11+
12+
public GraphAdjList(int vertexCount){
13+
this.vertexCount=vertexCount;
14+
vertices= new ArrayList<>();
15+
edges= new ListNode[vertexCount];
16+
for(int i=0; i< vertexCount; i++){
17+
vertices.add(i);
18+
edges[i]= new ListNode(0);
19+
}
20+
}
21+
22+
public void addEdge(int source, int destination){
23+
int i= vertices.indexOf(source);
24+
int j= vertices.indexOf(destination);
25+
26+
if(i != -1 && j != -1){
27+
// edges[i].insertAtBeginning(destination);
28+
// edges[j].insertAtBeginning(source);
29+
}
30+
}
31+
}

‎DataAndAlgoL/Chpt9GraphAlgorithms/Graph.java‎ renamed to ‎DataAndAlgoL/Chpt9GraphAlgorithms/GraphAdjMatrix.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package DataAndAlgoL.Chpt9GraphAlgorithms;
2-
//below class reads an undirected graph
3-
public class Graph {
2+
//Adjacency Matrix representation
3+
public class GraphAdjMatrix {
44
public boolean adjMatrix[][];
55
public int vertexCount;
66

77
//constructor
8-
public Graph(int vertexCount){
8+
public GraphAdjMatrix(int vertexCount){
99
this.vertexCount= vertexCount;
1010
adjMatrix= new boolean[vertexCount][vertexCount]; //boolean 2-d array as a matrix with a max amount o VxV vertices
1111
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /