int TKNP(int a[],int dau,int cuoi,int x)
{
int giua;
if(dau>cuoi) return -1;
giua=(dau+cuoi)/2;
if(x==a[giua]) return giua;
else if(x>a[giua]) return TKNP(a,giua+1,cuoi,x);
else return TKNP(a,dau,giua-1,x);
}
int Tim_kiem_nhi_phan(int a[], int X, int n)
{
int left = 0, right = n-1;
int mid;
while (left <= right)
{
mid = (left + right)/2;
if(X==a[mid]) return mid;
if (X >a[mid]) left = mid +1;//Tìm X o mang sau
else right =mid-1;// tim X o mang truoc
}
return -1; // khong tim thay x thi tra ve -1
}