Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 430c0aa

Browse files
Add files via upload
1 parent 00ddfaa commit 430c0aa

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

‎Algorithms/Array/rotated_search.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include<iostream>
2+
#include<conio.h>
3+
#include<stdlib.h>
4+
#include<bits/stdc++.h>
5+
6+
using namespace std;
7+
8+
int hello()
9+
{
10+
vector<int>arr(100);
11+
int n;
12+
cin>>n;
13+
for(int i=0;i<n;i++)
14+
{
15+
cin>>arr[i];
16+
}
17+
int target;
18+
cin>>target;
19+
int low=0,high=n-1;
20+
while(low<=high)
21+
{
22+
int mid=low+(high-low)/2;
23+
if(arr[mid]==target)return mid;
24+
if(arr[mid]>=arr[low])
25+
{
26+
if(target>=arr[low]&&target<arr[mid])
27+
high=mid-1;
28+
else
29+
low=mid+1;
30+
}
31+
else
32+
{
33+
if(target>arr[mid]&&target<=arr[high])
34+
low=mid+1;
35+
else
36+
high=mid-1;
37+
}
38+
}
39+
40+
}
41+
42+
main()
43+
{
44+
cout<<hello();
45+
46+
47+
return 0;
48+
}
49+
50+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /