I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value.
I.e.
if array[i + 1][j + 1] has the largest value among the 3 then move there.
I have 2 versions of this, but I think it can be cleaner.
version 1:
int maxI = i + 1;
int maxJ = j + 1;
if(array[i + 1][j] > array[maxI][maxJ]){
maxI = i + 1;
maxJ = j;
}
if(array[i][j + 1] > array[maxI][maxJ]){
maxI = i;
maxJ = j + 1;
}
i = maxI;
j = maxJ;
version 2:
if(LCS[i + 1][j + 1] > LCS[i][j + 1] && LCS[i + 1][j + 1] > LCS[i + 1][j]){
i++;
j++;
}
else{
if(LCS[i][j + 1] > LCS[i + 1][j]){
j++;
}
else{i++;}
}
Both versions occur in a while loop which I omitted for clarity.
How can these versions become better?
if-block, because it does not do anything. \$\endgroup\$