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

Version Path
trackler-2.2.1.180 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.179 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.178 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.177 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.176 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.175 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.174 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.173 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.172 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.171 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.170 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.169 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.167 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.166 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.165 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.164 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.163 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.162 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.161 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.160 tracks/c/exercises/binary-search/src/example.c