Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Ex14 here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Ex14
- {
- public static boolean search(int[][] mat, int num)
- {
- int rL = 0, rH = mat.length;
- int cL = 0, cH = mat.length;
- int pR = rL + (rH - rL)/2;
- int pC = cL + (cH - cL) / 2;
- for(int i = 0; i < Math.log(mat.length)/Math.log(2); i++)
- {
- pR = rL + (rH - rL)/2;
- pC = cL + (cH - cL) / 2;
- if(num >= mat[pR][0])
- {
- rL = pR;
- cH = pC;
- }
- else if(num >= mat[pR][pC])
- {
- rL = pR;
- cL = pC;
- }
- else if(num >= mat[0][pC])
- {
- rH = pR;
- cL = pC;
- }
- else
- {
- rH = pR;
- cH = pC;
- }
- }
- pR = rL + (rH - rL)/2;
- pC = cL + (cH - cL) / 2;
- return mat[pR][pC] == num;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement