Sha256: cb95a6cf0f1b52d11cddbbd487b223a593f819b75ad6170ad1f4860cae2157b0
Contents?: true
Size: 482 Bytes
Versions: 395
Compression:
Stored size: 482 Bytes
Contents
#include "binary_search.h" int *binary_search(const int value, const int *arr, const size_t length) { if (0 == length || NULL == arr) { return NULL; } const int *low = arr; const int *high = arr + length - 1; while (low <= high) { const int *mid = low + (high - low) / 2; if (*mid > value) { high = mid - 1; } else if (*mid < value) { low = mid + 1; } else { return (int *)mid; } } return NULL; }
Version data entries
395 entries across 395 versions & 1 rubygems