Skip to content

Commit 5b47ee4

Browse files
Merge pull request #416 from tiyarocks/master
Add files via upload
2 parents 6fdde67 + 0972a49 commit 5b47ee4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

stairCaseSearch.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include<iostream>
2+
using namespace std;
3+
int stairCaseSearch(int a[][100],int R, int C, int key)
4+
{
5+
int i=0,j=C-1;
6+
while(i<R && j>=0)
7+
{
8+
if(a[i][j]==key)
9+
{
10+
//cout<<"Found at position "<<i<<" "<<j<<endl;
11+
return 1;
12+
13+
}
14+
if(a[i][j]>key)
15+
{
16+
j--;
17+
18+
}
19+
else
20+
{
21+
i++;
22+
}
23+
24+
}
25+
//<<"Element not found";
26+
return 0;
27+
28+
}
29+
int main()
30+
{
31+
int arr[100][100],R,C,NUM,ch;
32+
cin>>R>>C;
33+
34+
35+
36+
for(int i=0; i<R; i++)
37+
{
38+
for(int j=0; j<C; j++)
39+
{
40+
cin>>arr[i][j];
41+
42+
}
43+
}
44+
cin>>NUM;
45+
ch=stairCaseSearch(arr,R,C,NUM);
46+
cout<<ch;
47+
48+
return 0;
49+
50+
}

0 commit comments

Comments
 (0)