-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorted_matrix_search.java
More file actions
41 lines (33 loc) · 898 Bytes
/
sorted_matrix_search.java
File metadata and controls
41 lines (33 loc) · 898 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
30
31
32
33
34
35
36
37
38
39
40
41
public class sorted_matrix_search {
public static void search(int a[][],int k){
int l=a.length;
int i=0,j=l-1;
boolean t=true;
while(i<l&&j>=0){
System.out.println("way " +a[i][j]);
if(k==a[i][j]&&j>=0){
System.out.println("element found at ("+i+","+j+") = "+a[i][j]+" :");
t=false;
break;
}
else if(k<a[i][j]){
j=j-1;
}
else {
i=i+1;
}
}
if(t){
System.out.println("element not found");
}
}
public static void main(String args[]){
int a[][]={
{10,20,30,40},
{15,25,35,45},
{27,29,37,48},
{32,33,39,50}
};
search(a,33);
}
}