Intelligent method for particular traversing of a matrix
Intelligent method for particular traversing of a matrix I have to traverse an n x n matrix in java (so indices are 0,...,n-1), to assign values to the single elements. I must start from the bottom right and arrive to the top left. The particularity is that I do not have to consider the matrix[n-1][n-1] element, that has been initialised before. The adjacent values depend on each other for initialazing and it must be initialized first. n x n matrix[n-1][n-1] One way could be inserting an if in the for cycle if for for (i = n-1; i >= 0; i--) for (j = n-1; j >= 0; j--) if (i == n - 1 && j == n - 1) //initialize particular value else //initialize others but it seems to me a bit inefficient. Another way could be to initialize the value matrix[n-1][n-1] outside the cycle, then doing 3 for cycles (one for the bottom line, one for the rightest column, one for the other elements). But it seems a bit inelegant. matrix[n-1][n-1] for So I'm searching,...
