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 311c87a

Browse files
committed
Chpt 3 continuation and chpt 9 start
chpt 9 start and circular linked list from chpt 3
1 parent 8efb125 commit 311c87a

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package DataAndAlgoL.Chp3LinkedLists;
2+
3+
public class CLLNode {
4+
public CLLNode next;
5+
public int data;
6+
7+
public CLLNode(int data){
8+
this.data= data;
9+
}
10+
11+
public void setData(int data){
12+
this.data= data;
13+
}
14+
15+
public int getData(){
16+
return data;
17+
}
18+
19+
//sets pointer to the next List node
20+
public void setNext(CLLNode next){
21+
this.next= next;
22+
}
23+
24+
//returns the next node at which previous node was pointing too
25+
public CLLNode getNext(){
26+
return this.next;
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package DataAndAlgoL.Chp3LinkedLists;
2+
3+
public class CoutingCLLNodes {
4+
public int CircularListLength(CLLNode head){
5+
int length=0;
6+
CLLNode currentNode= head.getNext();
7+
while (currentNode != head){
8+
length++;
9+
currentNode=currentNode.getNext();
10+
}
11+
12+
return length;
13+
}
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package DataAndAlgoL.Chpt9GraphAlgorithms;
2+
//below class reads an undirected graph
3+
public class Graph {
4+
public boolean adjMatrix[][];
5+
public int vertexCount;
6+
7+
//constructor
8+
public Graph(int vertexCount){
9+
this.vertexCount= vertexCount;
10+
adjMatrix= new boolean[vertexCount][vertexCount]; //boolean 2-d array as a matrix with a max amount o VxV vertices
11+
}
12+
//adding an edge between to vertices
13+
public void addEdge(int i, int j){
14+
if(i >=0 && i < vertexCount && j> 0 && j <vertexCount){
15+
adjMatrix[i][j]=true;
16+
adjMatrix[j][i]=true;
17+
}
18+
}
19+
20+
public void removeEdge(int i, int j){
21+
if(i >=0 && i < vertexCount && j> 0 && j <vertexCount){
22+
adjMatrix[i][j]=false;
23+
adjMatrix[j][i]=false;
24+
}
25+
}
26+
27+
public boolean isEdge(int i, int j){
28+
if(i >=0 && i < vertexCount && j> 0 && j <vertexCount){
29+
return adjMatrix[i][j]; //only if the edge is set to true which means it exists
30+
}else{
31+
return false;
32+
}
33+
}
34+
}

0 commit comments

Comments
(0)

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