What is wrong with this code?


#1

int firstSearch(int *a,int low, int high, int key,int n)
{ while(high>=low)
{
int mid=low+(low+high)/2;
if((mid==0 || key>a[mid-1]) && a[mid]==key)
return mid;
else if(key>a[mid])
firstSearch(a,(mid+1),high,key,n);
else
firstSearch(a,low,(mid-1),key,n);
}
return -1;
}

int lastSearch(int *a,int low, int high, int key,int n)
{
while(high>=low)
{
int mid=low+(low+high)/2;
if((mid==n-1 || key<a[mid+1]) && a[mid]==key)
return mid;
else if(key<a[mid])
lastSearch(a,low,(mid-1),key,n);
else
lastSearch(a,(mid+1),high,key,n);
}
return -1;
}

int findCount(const int* A, int n1, int B) {

int first=firstSearch(A,0,n1-1,B,n1);;
if(first==-1)
    return 0;
else
{ int last=lastSearch(A,0,n1-1,B,n1);
   return (last-first+1);
}

}