MCPcopy Create free account
hub / github.com/apna-college/Alpha / staircaseSearch

Method staircaseSearch

4_2DArrays/SearchInSorted.java:6–28  ·  view source on GitHub ↗
(int matrix[][], int key)

Source from the content-addressed store, hash-verified

4
5public class SearchInSorted {
6 public static boolean staircaseSearch(int matrix[][], int key) {
7 int n = matrix.length, m = matrix[0].length;
8 int i = 0, j = n-1;
9
10 while(j>=0 && i<n) {
11 if(matrix[i][j] == key) {
12 System.out.println("Found at (" + i +"," + j + ")");
13 return true;
14 }
15 //go down
16 else if(matrix[i][j] < key) {
17 i++;
18 }
19 //go left
20 else if(matrix[i][j] > key) {
21 j--;
22 }
23
24 }
25
26 System.out.println("NOT Found");
27 return false;
28 }
29 public static void main(String args[]) {
30 int matrix[][] = {{10, 20, 30, 40},
31 {15, 25, 35, 45},

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected