Commit d6ed47b7 authored by Preetham Poluparthi's avatar Preetham Poluparthi

change implementation to binary-search

parent ac7cd519
#include "main.cpp"
bool search_custom(vector<int> a,int num){
for(int i=0;i<a.size();i++){
if(a[i]==num)
return true;
}
return false;
int n=a.size();
int i=0,f=n-1;
while(true)
{
if(i==f)
{
if(a[i]==num) return true;
return false;
}
if(f==i+1)
{
if(a[i]==num) return true;
if(a[f]==num) return false;
return false;
}
int c=(i+f)/2;
if(a[c]==num) return true;
if(a[c]>num)
{
f=c-1;
}
else
{
i=c+1;
}
}
return false;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment