forked from KISHOREMUTHU/Data-Structures-And-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrot_sort_array.c
More file actions
41 lines (36 loc) · 746 Bytes
/
Copy pathrot_sort_array.c
File metadata and controls
41 lines (36 loc) · 746 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
//# Data-Structures-And-Algorithms
//Here I will post my regular DSA problems
//Search an element in Rotated sorted array
//Problem - 1
#include <stdio.h>
#include<string.h>
int main (){
int i,x,l,r,mid,m;
int a[8]={5,5,6,6,7,0,1,2};
scanf ("%d",&x);
l=0;
r=7;
while (l<=r){
mid=(l+r)/2;
if(a[mid]==x){
printf("%d",mid);
break;
}
else if(a[mid]>x){
if(a[l]<=x&&a[mid]>=x){
r=mid-1;
}
else{
l=mid+1;}}
else if(a[mid]<x){
if(a[mid]<=x&&a[r]>=x){
l=mid+1;
}
else{
r=mid-1;
}
}
else{
l++;}
}
}