原创 帮忙找bug

2008-11-6 16:29 2320 5 5 分类: 软件与OS
谁能找的出下面这个函数的bug么?

int findData(int a[], int array_len, int target)
{
            int low = 0;
            int high = array_len - 1;
            while(low <= high)
            {
                        int mid = (low+high)/2;
                        int value = a[mid];
                        if(target < value)
                                    high--;
                            else if(target > value)
                                       low++;
                              else
                                    return mid;
            }
            return -1;
}

文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /2 下一条