#include<stdio.h>
int main()
{
int element_count(int * set, int len, int e);
int set[10]={1,2,3,4,5,5,5,5,8,9};
printf("%d",element_count(set,10,5));
}
int element_count(int * set, int len, int e)
{
int mid,low,high;
int num=0;
int i;
low=0;
high=len-1;
while (low<=high)
{
mid=(low+high)/2;
if(set[mid]==e)
{
for(i=low;i<=high;i++)
{
if(set[i]==e)
num++;
}
return num;
}
else if(set[mid]>e)
{
high=mid-1;
}
else
{
low=mid+1;
}
}
}