I have a two dimensional array int matrix[numNodes][numArcs]. This is an Incidence matrix.
Now, if we wish to add an arc, we have to check those nodes exist and the arc does not exist. This part works well. The following thing i need to do, is find an empty column to add the arc. So the matrix is full of zeros at the beginning . So its simple, you search each column until you find a column full of zeros. Sounds simple but its now working. This part of the code is the following:
outerloop:
for (int i = 0; i < numArcs; i++){
for (int j = 0; j < numNodes; j++){
if (matriz[j][i] != 0)
break;
//It finds a number != 0 so it should move to the next column
//If it gets here, the whole column was full of zeros
column = i;
key = true;
break outerloop;
}
}
I use the key to know i found the column, because if i dont its because the matrix is full and i need to duplicate it. Thats another issue non-related to this problem.
Now, i tried to figure out the problem and i notice the following: its only checking these positions:
01
02
03
03
As you can see, its just checking the first position of each column and not going all the way down how it should. To me it makes no sense. NumNode is 10 in my example, so it should go all the way down.
Edit:
My exact example
the matrix is like this:
-1 -1 -1 0 0 0 ....
0 1 0 0 0 ...
0 0 1 0 0 .....
So when it reaches the fourth column, it reads that zero and return thats the empty column.
It does the same for the next n arcs I added. the following arcs i add don’t touch the first row any more.
thanks for the help
What if in the inner loop, you don’t break for the first time.. You will store
iinto column without checking other rows for that column..You can better use a boolean flag variable to check what you want..