#include<stdio.h>
int bSearch(int A[],int low,int high,int searchKey)
{
int position=-1;
int found=0;
int mid;
while(low<=high && !found)
{
mid=(low+high)/2;
if(A[mid]==searchKey)
{
position=mid;
found=1;
}
else if(searchKey<A[mid])
{
low=mid-1;
}
else
{
high=mid+1;
}
}
return position;
}
int main()
{
int arr1[]={5,12,23,28,35,42};
int key=35;
int position=bSearch(arr1,0,5,key);
if(position==-1)
{
printf("Element is not present");
}
else
{
printf("Element is present in index %d",position);
}
}
binary search algorithm ekk code ekak thiyenne. meka run karama run time error ekak enw.mokadda meke thiyena waradda. pls help brothers!
p.s- run time error-SIGTSTP
codeblocks wala tamai run kare
int bSearch(int A[],int low,int high,int searchKey)
{
int position=-1;
int found=0;
int mid;
while(low<=high && !found)
{
mid=(low+high)/2;
if(A[mid]==searchKey)
{
position=mid;
found=1;
}
else if(searchKey<A[mid])
{
low=mid-1;
}
else
{
high=mid+1;
}
}
return position;
}
int main()
{
int arr1[]={5,12,23,28,35,42};
int key=35;
int position=bSearch(arr1,0,5,key);
if(position==-1)
{
printf("Element is not present");
}
else
{
printf("Element is present in index %d",position);
}
}
binary search algorithm ekk code ekak thiyenne. meka run karama run time error ekak enw.mokadda meke thiyena waradda. pls help brothers!
p.s- run time error-SIGTSTP
codeblocks wala tamai run kare
Last edited: