I currently have a nxn array of ints. I plan to initialize all the cells within the array with infinity and later change it if a value being compared to the cell is lower than the value inside the cell. Here is the pseudo-code of what I came up with so far, using -1 to represent infinity. What do you think? Is this the most efficient way, any bugs?
if(table[i][j] == -1 || (table[i][j] != -1 && table[i][j] > value)
then table[i][j] = value
I would instead start with
Integer.MAX_VALUE. This way, the code could be simpler :Notice that, were your array to contain doubles, you could even go as far as using
Double.POSITIVE_INFINITY.