For example, the following two-dimensional array is each row, each column is an ascending sort. Returns True if the number 7 is found in this array, or FALSE if you look for an array of 5, because the array does not contain the number.
1 2 8 9
2 4 9 12
4 7 10 13
6 8 11 15 First we select the number in the upper-right corner of the array 9. Because 9 is greater than 7, and 9 is the first (and smallest) number in column 4th, so 7 can't be in the column where the number 9 is, so just analyze the remaining 3 columns, and in the rest of the matrix, the number in the upper-right corner is 8. Also 8 is greater than 7, so the column for 8 can also be removed. Next, just analyze the remaining two columns, and as 2 is less than 7, the 7 you are looking for may be on the right and bottom of 2. Since the right side of the 2 has been removed, it is only possible to appear below 2, to remove 2 of the row, leaving only three rows two columns, and then the same way as before, when found that the end of the 7 o'clock. The summary rule is as follows: First, select the number in the upper-right corner of the matrix. If it is equal to the number you are looking for, the lookup process ends; if it is greater than the number you are looking for, the column that contains the number is excluded, or the row that contains the number is excluded if it is less than the number you are looking for. Each step can reduce the lookup range until you find the number you want to find, or find the failure.
Public static boolean getvaluefrommatrix (int[][] sample, int rows, int columns, int num) { boolean found = false; if (sample != null && rows > 0 && columns > 0) { int row = 0; int column = columns - 1; while (row < rows && column >= 0) &NBSP;{&NBsp; int tempValue = sample[row][column]; if (num > Tempvalue) { ++row; } else if (num < tempvalue) { --column; } else { found = true; break; } } } return found; }