RECURSIVE BINARY SEARCH
This program illustrates the use of Binary Search.
#include"stdio.h"
main()
{
int t[10];
int a,mid,first,last,key,b,d;
clrscr();
for(a=0;a<10;a++)
scanf("%d",&t[a]);
printf("enter element:");
scanf("%d",&key);
for(a=0;a<10;a++)
for(b=0;b<10;b++)
if(t[a]
{
d=t[a];t[a]=t[b];t[b]=d;
}
last=9;
first=0;
a=f(t,first,last,key);
a==1?printf("key found"):printf("key not found");
getch();
}
f(int t[10],int first,int last,int key)
{
int found=0,mid;
if(first>last)
return(0);
mid=(first+last)/2;
if(key
{
last=mid-1;
}
if(key>t[mid])
first=mid+1;
if(key==t[mid])
return(1);
f(t,first,last,key);
}