Algorithms Summary: prove safety offer (Digital lookup)

A two-dimensional array of digital Find

    Title: two-dimensional array, each row is incremented from left to right, top to bottom of each column is incremented; the completion of a function: the input digital array to be searched and determines whether this number can be found;

// starting from the upper right array query, the query result is determined according to the change in the subject in rows and columns, and gradually narrow down 
Private static Boolean findValueInMatrix (Integer [] [] Number, Integer Key) { int rowLength = number.length; int columnLength = Number [0 ] .length; Boolean bFindFlag = to false ; IF (rowLength> 0 && columnLength> 0 ) { int rowIndex = 0 ; int columnIndex columnLength = -. 1 ; the while (rowIndex <rowLength && columnIndex> = 0 ) { IF (Number [rowIndex] [columnIndex] == Key) { bFindFlag = to true ; BREAK ; } IF (Number [rowIndex] [columnIndex]> Key) { columnIndex - ; // Key value is less than the current column, the next step in the left column of the query } the else { rowIndex ++ ; // Key value larger than the current line, the next line the next query } } } return bFindFlag; }

 

Guess you like

Origin www.cnblogs.com/clarino/p/11764051.html