首页 > 代码库 > 常用算法

常用算法

二分查找

int  binary_search(int a[],int len,int goal){    int beg = 0;    int end = len - 1;    while(beg <= end)    {        int middle = (end + beg + 1)/2;        if(a[middle] == goal)            return middle;        if(a[middle] > goal)            end = middle - 1;        else            beg = middle + 1;    }    return -1;}

 

常用算法