Untitled
raw download clone
C
views 12
,
size 348 b
#include "function.h"

int BS(int* a, int tar, int r)
{
    int L = 0;
    int R = r;
    int ans, mid;
    while (L < R)
    {
        mid = (L + R) / 2;
        if (a[mid] > tar) R = mid;
        else if (a[mid] < tar) L = mid + 1;
        else
        {
            ans = mid;
            break;
        }
    }
	return ans;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.