-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorted.java
More file actions
25 lines (24 loc) · 800 Bytes
/
Copy pathsorted.java
File metadata and controls
25 lines (24 loc) · 800 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
public class sorted {
public static boolean staircaseSearch(int[][] matrix, int key) {
int row = 0, col =matrix[0].length-1;
while(row< matrix.length && col>=0) {
if(matrix[row][col] == key) {
System.out.println("Found the element at row " + row + " and col " + col);
return true;
}
else if(key < matrix[row][col]) {
col--;
}
else {
row++;
}
}
System.out.println("key not found");
return false;
}
public static void main(String[] args) {
int [][] matrix = {{10,20,30,40},{15,25,35,45},{27,29,37,48},{32,33,39,50}};
int key = 33;
staircaseSearch(matrix, key);
}
}