I am not sure if title correctly relates to my problem, feel free to amend it! :)
What i am trying to do is, visit a m x n matrix in java and simultaneously mark the visited nodes based on certain condition
//int a[][] = new int[5][5];
for(int i = 0;i< a.length;i++) //row
for(int k = 0;k<a[0].length;k++) //column
if((i+k) % 3 ==0 ) //condition
a[i][k].visited = true;
else
a[i][k].visited = false;
In memory, i am imagining it something like :
_ _ _ _
| |
|a[0][3]| - > Visited //(for true)
|_ _ _ _|
But i am getting Error :
visited can not be resolved or is not a field
Can some one please help me on how to mark array blocks, or for instance, associate any value to them, like, just for example :
a[i][i].name = "Boston"
a[i][i].country = "India"
Dummy Program I am using, similar to my actual code
class TestingGround {
int a[][] = new int[5][5];
boolean visited = false;
public static void main(String[] args) {
TestingGround tg = new TestingGround();
tg.runner();
}
void runner()
{
for(int i = 0;i< a.length;i++)
for(int k = 0;k<a[0].length;k++)
if((i+k) % 3 ==0 )
a[i][k].visited = true;
else
a[i][k].visited = false;
}
}
acontains numeric values which are distance, take it as a graph holding distance between 2 different places denoted byiandk...so i have to mark the city that i have visited already, to avoid infinite loops!