-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixSearch.java
More file actions
29 lines (27 loc) · 876 Bytes
/
Copy pathmatrixSearch.java
File metadata and controls
29 lines (27 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class matrixSearch {
public static int StairSearch(int arr[][], int key){
int row = 0, col = arr[0].length-1;
while(row <arr.length && col >= 0){
if(arr[row][col]== key){
System.out.println("Found at "+ row + "," + col);
return key;
}
else if(arr[row][col] > key){
col --;
}
else{
row ++;
}
}
System.out.println("Key not found");
return -1;
}
public static void main(String args[]){
int arr[][] = {{10,20,30,40},
{15,25,35,45},
{27,29,37,48},
{32,33,39,50}};
int key = 39;
StairSearch(arr, key);
}
}