//add adj nodes
try{
for(int r2 = 0; r2 < rows; r2++){
for(int c2 = 0; c2 < cols; c2++){
Node currentNode = nodeGrid[r2][c2];
Node rightNode = nodeGrid[r2][c2+1];
Node bottomNode = nodeGrid[r2+1][c2];
if(!rightNode.isWall()){
currentNode.addNeighbor(rightNode);
}
if(!bottomNode.isWall()){
currentNode.addNeighbor(bottomNode);
}
}
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("no next node");
}
Hello, given that i have this 2D array, and i would like to access the next element i would eventually reach a index out of bounds, is there any other workaround for accessing the next element?
if (c2 + 1 < cols)