Add Assumption Comments
This commit is contained in:
parent
948efc0606
commit
7d5a965668
|
@ -34,7 +34,7 @@ public class ArrayUtility {
|
||||||
if(n<=0) return new int[0][0]; //Return to prevent ArithmeticException: / by zero and negative array index
|
if(n<=0) return new int[0][0]; //Return to prevent ArithmeticException: / by zero and negative array index
|
||||||
if (d.length%n!=0)return new int[0][0]; //Return, empty array, array can't be split into n equal parts
|
if (d.length%n!=0)return new int[0][0]; //Return, empty array, array can't be split into n equal parts
|
||||||
int[][] splittedArray = new int[n][d.length/n]; //Create the splitted_array array and initialize it
|
int[][] splittedArray = new int[n][d.length/n]; //Create the splitted_array array and initialize it
|
||||||
for(int i = 0;i < n;i++)for(int j = 0;j<d.length/n;j++)splittedArray[i][j] = d[i*(d.length/n)+j];//Loop for n Row and d.length/n column, the position of 2d array is row * ROW_SIZE + column
|
for(int i = 0;i < n;i++)for(int j = 0;j<d.length/n;j++)splittedArray[i][j] = d[i*(d.length/n)+j];//Loop for n Row and d.length/n column, the position of 2d array is row * ROW_SIZE + column, This assumption is only valid if ROW_SIZE are static (Splitted Array Are Rectangular)
|
||||||
return splittedArray; //send the reference back
|
return splittedArray; //send the reference back
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue