Untitled
raw download clone
TEXT
views 19
,
size 404 b
#include"function.h"

int BS(int* str, int target, int n)
{
    int L = 0;
    int R = n;

    while(L < R)
    {
        int mid = (L+R)/2;

        if(target > str[mid])
        {
            L = mid;
        }

        else if(target < str[mid])
        {
            R = mid;
        }

        else if(target == str[mid])
        {
            return mid;
        }
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.